本文整理汇总了C#中Voat.Models.whoaverseEntities类的典型用法代码示例。如果您正苦于以下问题:C# whoaverseEntities类的具体用法?C# whoaverseEntities怎么用?C# whoaverseEntities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
whoaverseEntities类属于Voat.Models命名空间,在下文中一共展示了whoaverseEntities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendPrivateMessage
// a method to send a private message to a user, invoked by other methods
public static bool SendPrivateMessage(string sender, string recipient, string subject, string body)
{
using (var db = new whoaverseEntities())
{
try
{
var privateMessage = new Privatemessage
{
Sender = sender,
Recipient = recipient,
Timestamp = DateTime.Now,
Subject = subject,
Body = body,
Status = true,
Markedasunread = true
};
db.Privatemessages.Add(privateMessage);
db.SaveChanges();
return true;
}
catch (Exception)
{
return false;
}
}
}
示例2: PullsDefaultFrontpage
public void PullsDefaultFrontpage(whoaverseEntities db, Defaultsubverse defaultsubverse, List<Message> messages)
{
// Arrange
// TODO: See if we can coax Autofixture into handling this for us
if (defaultsubverse.name.Length > 20)
defaultsubverse.name = defaultsubverse.name.Substring(0, 19);
db.Defaultsubverses.Add(defaultsubverse);
db.Subverses.Add(new Subverse {name = defaultsubverse.name, title = new Guid().ToString()});
db.SaveChanges();
foreach (var message in messages)
{
// TODO: See if we can coax Autofixture into handling this for us
if (message.Thumbnail.Length > 40)
message.Thumbnail = message.Thumbnail.Substring(0, 39);
message.Subverse = defaultsubverse.name;
}
db.Messages.AddRange(messages);
db.SaveChanges();
var homeController = new HomeController(db);
homeController.ControllerContext = GetControllerContext(false);
// Act
var actionResult = (ViewResult) homeController.Index(null);
var model = (PaginatedList<Message>) actionResult.Model;
// Assert
Assert.True(model.Count == messages.Count);
}
示例3: CheckIfSavedComment
// returns true if saved, false otherwise
public static bool? CheckIfSavedComment(string userToCheck, int commentId)
{
using (var db = new whoaverseEntities())
{
return db.Commentsavingtrackers.Where(b => b.CommentId == commentId && b.UserName == userToCheck).AsNoTracking().Any();
}
}
示例4: BadgeInfo
public ApiBadge BadgeInfo(string badgeId)
{
ApiBadge badgeInfo = CacheHandler.Register<ApiBadge>(String.Format("LegacyApi.ApiBadge.{0}", badgeId),
new Func<ApiBadge>(() =>
{
using (whoaverseEntities db = new whoaverseEntities(CONSTANTS.CONNECTION_READONLY))
{
var badge = _db.Badges.Find(badgeId);
if (badge == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var resultModel = new ApiBadge
{
BadgeId = badge.BadgeId,
BadgeGraphics = badge.BadgeGraphics,
Name = badge.BadgeName,
Title = badge.BadgeTitle
};
return resultModel;
}
}), TimeSpan.FromHours(5));
return badgeInfo;
}
示例5: SaveComment
// a user wishes to save a comment, save it
public static void SaveComment(int commentId, string userWhichSaved)
{
var result = CheckIfSavedComment(userWhichSaved, commentId);
using (var db = new whoaverseEntities())
{
if (result == true)
{
// Already saved, unsave
UnSaveComment(userWhichSaved, commentId);
}
else
{
// register save
var tmpSavingTracker = new Commentsavingtracker
{
CommentId = commentId,
UserName = userWhichSaved,
Timestamp = DateTime.Now
};
db.Commentsavingtrackers.Add(tmpSavingTracker);
db.SaveChanges();
}
}
}
示例6: CheckIfSaved
// returns true if saved, false otherwise
public static bool? CheckIfSaved(string userToCheck, int messageId)
{
using (var db = new whoaverseEntities())
{
return db.Savingtrackers.Where(u => u.UserName == userToCheck && u.MessageId == messageId).AsNoTracking().Any();
}
}
示例7: CheckIfSavedComment
// returns true if saved, false otherwise
public static bool? CheckIfSavedComment(string userToCheck, int commentId)
{
using (whoaverseEntities db = new whoaverseEntities())
{
var cmd = db.Database.Connection.CreateCommand();
cmd.CommandText = "SELECT COUNT(*) FROM Commentsavingtracker WITH (NOLOCK) WHERE UserName = @UserName AND CommentId = @CommentId";
var param = cmd.CreateParameter();
param.ParameterName = "UserName";
param.DbType = System.Data.DbType.String;
param.Value = userToCheck;
cmd.Parameters.Add(param);
param = cmd.CreateParameter();
param.ParameterName = "CommentId";
param.DbType = System.Data.DbType.String;
param.Value = commentId;
cmd.Parameters.Add(param);
if (cmd.Connection.State != System.Data.ConnectionState.Open)
{
cmd.Connection.Open();
}
int count = (int)cmd.ExecuteScalar();
return count > 0;
}
//using (var db = new whoaverseEntities())
//{
// return db.Commentsavingtrackers.Where(b => b.CommentId == commentId && b.UserName == userToCheck).AsNoTracking().Any();
//}
}
示例8: SaveSubmission
// a user wishes to save a submission, save it
public static void SaveSubmission(int submissionId, string userWhichSaved)
{
var result = CheckIfSaved(userWhichSaved, submissionId);
using (var db = new whoaverseEntities())
{
if (result == true)
{
// Already saved, unsave
UnSaveSubmission(userWhichSaved, submissionId);
}
else
{
// register save
var tmpSavingTracker = new Savingtracker
{
MessageId = submissionId,
UserName = userWhichSaved,
Timestamp = DateTime.Now
};
db.Savingtrackers.Add(tmpSavingTracker);
db.SaveChanges();
}
}
}
示例9: CustomCssDisabledForUser
// check if a given user does not want to see custom CSS styles
public static bool CustomCssDisabledForUser(string userName)
{
using (var db = new whoaverseEntities())
{
var result = db.Userpreferences.Find(userName);
return result != null && result.Disable_custom_css;
}
}
示例10: AdultContentEnabled
// check if a given user wants to see NSFW (adult) content
public static bool AdultContentEnabled(string userName)
{
using (var db = new whoaverseEntities())
{
var result = db.Userpreferences.Find(userName);
return result != null && result.Enable_adult_content;
}
}
示例11: CommentRepliesCount
// get total number of comment replies for a given user
public static int CommentRepliesCount(string userName)
{
using (var db = new whoaverseEntities())
{
var commentReplies = db.Commentreplynotifications.Where(s => s.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase));
if (!commentReplies.Any()) return 0;
return commentReplies.Any() ? commentReplies.Count() : 0;
}
}
示例12: UnSaveComment
// a user has saved this comment earlier and wishes to unsave it, delete the record
private static void UnSaveComment(string userWhichSaved, int commentId)
{
using (var db = new whoaverseEntities())
{
var votingTracker = db.Commentsavingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userWhichSaved);
if (votingTracker == null) return;
// delete vote history
db.Commentsavingtrackers.Remove(votingTracker);
db.SaveChanges();
}
}
示例13: UnSaveSubmission
// a user has saved this submission earlier and wishes to unsave it, delete the record
private static void UnSaveSubmission(string userWhichSaved, int messageId)
{
using (var db = new whoaverseEntities())
{
var saveTracker = db.Savingtrackers.FirstOrDefault(b => b.MessageId == messageId && b.UserName == userWhichSaved);
if (saveTracker == null) return;
//delete vote history
db.Savingtrackers.Remove(saveTracker);
db.SaveChanges();
}
}
示例14: CheckIfVoted
// returns -1:downvoted, 1:upvoted, 0:not voted
public static int CheckIfVoted(string userToCheck, int messageId)
{
using (var db = new whoaverseEntities())
{
var checkResult = db.Votingtrackers.Where(u => u.UserName == userToCheck && u.MessageId == messageId)
.AsNoTracking()
.FirstOrDefault();
int intCheckResult = checkResult != null ? checkResult.VoteStatus.Value : 0;
return intCheckResult;
}
}
示例15: CheckIfVotedComment
// returns -1:downvoted, 1:upvoted, or 0:not voted
public static int CheckIfVotedComment(string userToCheck, int commentId)
{
int intCheckResult = 0;
using (var db = new whoaverseEntities())
{
var checkResult = db.Commentvotingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userToCheck);
intCheckResult = checkResult != null ? checkResult.VoteStatus.Value : 0;
return intCheckResult;
}
}