当前位置: 首页>>代码示例>>C#>>正文


C# voatEntities.SaveChanges方法代码示例

本文整理汇总了C#中Voat.Models.voatEntities.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# voatEntities.SaveChanges方法的具体用法?C# voatEntities.SaveChanges怎么用?C# voatEntities.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Voat.Models.voatEntities的用法示例。


在下文中一共展示了voatEntities.SaveChanges方法的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 voatEntities())
            {
                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;
                }
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:29,代码来源:MesssagingUtility.cs

示例2: BlockSubverse

        // block a subverse
        public static void BlockSubverse(string userName, string subverse)
        {
            using (var db = new voatEntities())
            {
                // unblock if subverse is already blocked
                if (IsUserBlockingSubverse(userName, subverse))
                {
                    var subverseBlock = db.UserBlockedSubverses.FirstOrDefault(n => n.SubverseName.ToLower() == subverse.ToLower() && n.Username == userName);
                    if (subverseBlock != null) db.UserBlockedSubverses.Remove(subverseBlock);
                    db.SaveChanges();
                    return;
                }

                // add a new block
                var blockedSubverse = new UserBlockedSubverse { Username = userName, SubverseName = subverse };
                db.UserBlockedSubverses.Add(blockedSubverse);
                db.SaveChanges();
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:20,代码来源:User.cs

示例3: SubscribeToSubverse

        // subscribe to a subverse
        public static void SubscribeToSubverse(string userName, string subverse)
        {
            if (IsUserSubverseSubscriber(userName, subverse)) return;
            using (var db = new voatEntities())
            {
                // add a new subscription
                var newSubscription = new Subscription { Username = userName, SubverseName = subverse };
                db.Subscriptions.Add(newSubscription);

                // record new subscription in subverse table subscribers field
                Subverse tmpSubverse = db.Subverses.Find(subverse);

                if (tmpSubverse != null)
                {
                    tmpSubverse.subscribers++;
                }

                db.SaveChanges();
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:21,代码来源:User.cs

示例4: SubscribeToSet

        // subscribe to a set
        public static void SubscribeToSet(string userName, int setId)
        {
            // do nothing if user is already subscribed
            if (IsUserSetSubscriber(userName, setId)) return;

            using (var db = new voatEntities())
            {
                // add a new set subscription
                var newSubscription = new Usersetsubscription { Username = userName, Set_id = setId };
                db.Usersetsubscriptions.Add(newSubscription);

                // record new set subscription in sets table subscribers field
                var tmpUserSet = db.Usersets.Find(setId);

                if (tmpUserSet != null)
                {
                    tmpUserSet.Subscribers++;
                }

                db.SaveChanges();
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:23,代码来源:User.cs

示例5: DeleteUser

        // delete a user account and all history: comments, posts and votes
        public static bool DeleteUser(string userName)
        {
            using (var db = new voatEntities())
            {
                using (var tmpUserManager = new UserManager<VoatUser>(new UserStore<VoatUser>(new ApplicationDbContext())))
                {
                    var tmpuser = tmpUserManager.FindByName(userName);
                    if (tmpuser != null)
                    {
                        // remove voting history for submisions
                        db.Votingtrackers.RemoveRange(db.Votingtrackers.Where(x => x.UserName == userName));

                        // remove voting history for comments
                        db.Commentvotingtrackers.RemoveRange(db.Commentvotingtrackers.Where(x => x.UserName == userName));

                        // remove all comments
                        var comments = db.Comments.Where(c => c.Name == userName).ToList();
                        foreach (Comment c in comments)
                        {
                            c.Name = "deleted";
                            c.CommentContent = "deleted by user";
                        }
                        db.SaveChanges();

                        // remove all submissions
                        var submissions = db.Messages.Where(c => c.Name == userName).ToList();
                        foreach (Message s in submissions)
                        {
                            if (s.Type == 1)
                            {
                                s.Name = "deleted";
                                s.MessageContent = "deleted by user";
                                s.Title = "deleted by user";
                            }
                            else
                            {
                                s.Name = "deleted";
                                s.Linkdescription = "deleted by user";
                                s.MessageContent = "http://voat.co";
                            }
                        }

                        // resign from all moderating positions
                        db.SubverseAdmins.RemoveRange(db.SubverseAdmins.Where(m => m.Username.Equals(userName, StringComparison.OrdinalIgnoreCase)));

                        // delete comment reply notifications
                        db.Commentreplynotifications.RemoveRange(db.Commentreplynotifications.Where(crp => crp.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase)));

                        // delete post reply notifications
                        db.Postreplynotifications.RemoveRange(db.Postreplynotifications.Where(prp => prp.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase)));

                        // delete private messages
                        db.Privatemessages.RemoveRange(db.Privatemessages.Where(pm => pm.Recipient.Equals(userName, StringComparison.OrdinalIgnoreCase)));

                        // TODO:
                        // keep this updated as new features are added (delete sets etc)

                        // username will stay permanently reserved

                        db.SaveChanges();

                        return true;
                    }
                    // user account could not be found
                    return false;
                }

            }
        }
开发者ID:scott71,项目名称:voat,代码行数:70,代码来源:User.cs

示例6: DownvoteSubmission

        // submit submission downvote
        public static void DownvoteSubmission(int submissionId, string userWhichDownvoted, string clientIp)
        {
            int result = CheckIfVoted(userWhichDownvoted, submissionId);

            using (var db = new voatEntities())
            {
                Message submission = db.Messages.Find(submissionId);

                // do not execute downvoting if subverse is in anonymized mode
                if (submission.Anonymized)
                {
                    return;
                }

                // do not execute downvoting if user has insufficient CCP for target subverse
                if (Karma.CommentKarmaForSubverse(userWhichDownvoted, submission.Subverse) < submission.Subverses.minimumdownvoteccp)
                {
                    return;
                }

                switch (result)
                {
                    // never voted before
                    case 0:
                        {
                            // this user is downvoting more than upvoting, don't register the downvote
                            if (User.IsUserCommentVotingMeanie(userWhichDownvoted))
                            {
                                return;
                            }

                            // check if this IP already voted on the same submission, abort voting if true
                            var ipVotedAlready = db.Votingtrackers.Where(x => x.MessageId == submissionId && x.ClientIpAddress == clientIp);
                            if (ipVotedAlready.Any()) return;

                            submission.Dislikes++;

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;

                            // register downvote
                            var tmpVotingTracker = new Votingtracker
                            {
                                MessageId = submissionId,
                                UserName = userWhichDownvoted,
                                VoteStatus = -1,
                                Timestamp = DateTime.Now,
                                ClientIpAddress = clientIp
                            };
                            db.Votingtrackers.Add(tmpVotingTracker);
                            db.SaveChanges();

                            SendVoteNotification(submission.Name, "downvote");
                        }

                        break;

                    // upvoted before, turn upvote to downvote
                    case 1:
                        {
                            submission.Likes--;
                            submission.Dislikes++;

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;

                            // register Turn DownVote To UpVote
                            var votingTracker = db.Votingtrackers.FirstOrDefault(b => b.MessageId == submissionId && b.UserName == userWhichDownvoted);

                            if (votingTracker != null)
                            {
                                votingTracker.VoteStatus = -1;
                                votingTracker.Timestamp = DateTime.Now;
                            }
                            db.SaveChanges();

                            SendVoteNotification(submission.Name, "uptodownvote");
                        }

                        break;

                    // downvoted before, reset
                    case -1:
                        {
                            submission.Dislikes--;

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;
                            db.SaveChanges();

//.........这里部分代码省略.........
开发者ID:scott71,项目名称:voat,代码行数:101,代码来源:Voting.cs

示例7: UpvoteSubmission

        // submit submission upvote
        public static void UpvoteSubmission(int submissionId, string userWhichUpvoted, string clientIp)
        {
            // user account voting check
            int result = CheckIfVoted(userWhichUpvoted, submissionId);

            using (var db = new voatEntities())
            {
                Message submission = db.Messages.Find(submissionId);

                if (submission.Anonymized)
                {
                    // do not execute voting, subverse is in anonymized mode
                    return;
                }

                switch (result)
                {
                    // never voted before
                    case 0:

                        if (submission.Name != userWhichUpvoted)
                        {
                            // check if this IP already voted on the same submission, abort voting if true
                            var ipVotedAlready = db.Votingtrackers.Where(x => x.MessageId == submissionId && x.ClientIpAddress == clientIp);
                            if (ipVotedAlready.Any()) return;

                            submission.Likes++;
                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);
                            submission.Rank = newRank;

                            // register upvote
                            var tmpVotingTracker = new Votingtracker
                            {
                                MessageId = submissionId,
                                UserName = userWhichUpvoted,
                                VoteStatus = 1,
                                Timestamp = DateTime.Now,
                                ClientIpAddress = clientIp
                            };

                            db.Votingtrackers.Add(tmpVotingTracker);
                            db.SaveChanges();

                            SendVoteNotification(submission.Name, "upvote");
                        }

                        break;

                    // downvoted before, turn downvote to upvote
                    case -1:

                        if (submission.Name != userWhichUpvoted)
                        {
                            submission.Likes++;
                            submission.Dislikes--;

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);
                            submission.Rank = newRank;

                            // register Turn DownVote To UpVote
                            var votingTracker = db.Votingtrackers.FirstOrDefault(b => b.MessageId == submissionId && b.UserName == userWhichUpvoted);

                            if (votingTracker != null)
                            {
                                votingTracker.VoteStatus = 1;
                                votingTracker.Timestamp = DateTime.Now;
                            }
                            db.SaveChanges();

                            SendVoteNotification(submission.Name, "downtoupvote");
                        }

                        break;

                    // upvoted before, reset
                    case 1:
                        {
                            submission.Likes--;

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;
                            db.SaveChanges();

                            ResetMessageVote(userWhichUpvoted, submissionId);

                            SendVoteNotification(submission.Name, "downvote");
                        }

                        break;
                }
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:100,代码来源:Voting.cs

示例8: DownvoteComment

        // submit submission downvote
        public static void DownvoteComment(int commentId, string userWhichDownvoted, string clientIpHash)
        {
            int result = CheckIfVotedComment(userWhichDownvoted, commentId);

            using (voatEntities db = new voatEntities())
            {
                Comment comment = db.Comments.Find(commentId);

                // do not execute downvoting, subverse is in anonymized mode
                if (comment.Message.Anonymized)
                {
                    return;
                }

                // do not execute downvoting if user has insufficient CCP for target subverse
                if (Karma.CommentKarmaForSubverse(userWhichDownvoted, comment.Message.Subverse) < comment.Message.Subverses.minimumdownvoteccp)
                {
                    return;
                }

                switch (result)
                {
                    // never voted before
                    case 0:

                    {
                        // this user is downvoting more than upvoting, don't register the downvote
                        if (User.IsUserCommentVotingMeanie(userWhichDownvoted))
                        {
                            return;
                        }

                        // check if this IP already voted on the same comment, abort voting if true
                        var ipVotedAlready = db.Commentvotingtrackers.Where(x => x.CommentId == commentId && x.ClientIpAddress == clientIpHash);
                        if (ipVotedAlready.Any()) return;

                        comment.Dislikes++;

                        // register downvote
                        var tmpVotingTracker = new Commentvotingtracker
                        {
                            CommentId = commentId,
                            UserName = userWhichDownvoted,
                            VoteStatus = -1,
                            Timestamp = DateTime.Now,
                            ClientIpAddress = clientIpHash
                        };
                        db.Commentvotingtrackers.Add(tmpVotingTracker);
                        db.SaveChanges();

                        SendVoteNotification(comment.Name, "downvote");
                    }

                        break;

                    // upvoted before, turn upvote to downvote
                    case 1:

                    {
                        comment.Likes--;
                        comment.Dislikes++;

                        //register Turn DownVote To UpVote
                        var votingTracker = db.Commentvotingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userWhichDownvoted);

                        if (votingTracker != null)
                        {
                            votingTracker.VoteStatus = -1;
                            votingTracker.Timestamp = DateTime.Now;
                        }
                        db.SaveChanges();

                        SendVoteNotification(comment.Name, "uptodownvote");
                    }

                        break;

                    // downvoted before, reset
                    case -1:

                        comment.Dislikes--;
                        db.SaveChanges();
                        ResetCommentVote(userWhichDownvoted, commentId);

                        SendVoteNotification(comment.Name, "upvote");

                        break;
                }
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:91,代码来源:VotingComments.cs

示例9: UnSubscribeFromSubverse

        // unsubscribe from a subverse
        public static void UnSubscribeFromSubverse(string userName, string subverse)
        {
            if (IsUserSubverseSubscriber(userName, subverse))
            {
                using (var db = new voatEntities())
                {
                    var subscription = db.Subscriptions.FirstOrDefault(b => b.Username == userName && b.SubverseName == subverse);

                    if (subverse == null) return;
                    // remove subscription record
                    db.Subscriptions.Remove(subscription);

                    // record new unsubscription in subverse table subscribers field
                    Subverse tmpSubverse = db.Subverses.Find(subverse);

                    if (tmpSubverse != null)
                    {
                        tmpSubverse.subscribers--;
                    }

                    db.SaveChanges();
                }
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:25,代码来源:User.cs

示例10: 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 voatEntities())
            {
                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();
                }
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:26,代码来源:Saving.cs

示例11: Add

        // add a new session
        public static void Add(string subverseName, string sessionId)
        {
            try
            {
                if (SessionExists(sessionId, subverseName)) return;
                using (var db = new voatEntities())
                {
                    var newSession = new Sessiontracker { SessionId = sessionId, Subverse = subverseName, Timestamp = DateTime.Now };

                    db.Sessiontrackers.Add(newSession);
                    db.SaveChanges();

                }
            }
            catch (Exception)
            {
                //
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:20,代码来源:SessionTracker.cs

示例12: RemoveAllSessions

 // clear all sessions
 public static void RemoveAllSessions()
 {
     try
     {
         using (var db = new voatEntities())
         {
             db.Database.ExecuteSqlCommand("TRUNCATE TABLE SESSIONTRACKER");
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         //
     }
 }
开发者ID:scott71,项目名称:voat,代码行数:16,代码来源:SessionTracker.cs

示例13: Remove

 // remove a session
 public static void Remove(string sessionIdToRemove)
 {
     try
     {
         using (var db = new voatEntities())
         {
             // remove all records for given session id
             db.Sessiontrackers.RemoveRange(db.Sessiontrackers.Where(s => s.SessionId == sessionIdToRemove));
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         //
     }
 }
开发者ID:scott71,项目名称:voat,代码行数:17,代码来源:SessionTracker.cs

示例14: 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 voatEntities())
            {
                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();
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:13,代码来源:SavingComments.cs

示例15: 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 voatEntities())
            {
                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();
                }
            }
        }
开发者ID:scott71,项目名称:voat,代码行数:26,代码来源:SavingComments.cs


注:本文中的Voat.Models.voatEntities.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。