Exemplo n.º 1
0
        public static void DeleteResponse(int messageId, string userId, out StringBuilder errors)//Can be used for deleting a response or marking a response as read.
        {
            try
            {
                using (var db = new ApplicationDbContext())
                {
                    errors = new StringBuilder();
                    Message         message = GetMessageById(messageId);
                    ApplicationUser user    = UserRoles.GetUserById(userId);
                    Post            post    = UserPost.GetPostById(message.postId);

                    if (!MessageAction.CanUpdateMessageDatabase(message, user, post))
                    {
                        errors.Append("Can't delete Message");
                        return;
                    }
                    message.Deleted = true;
                    db.Messages.AddOrUpdate(message);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public void RequiredUserToDelete()
        {
            var post = GetPostWithMessages();

            foreach (var m in post.Messages)
            {
                Assert.IsFalse(MessageAction.CanUpdateMessageDatabase(m, null, post));
            }
        }
        public void NotSenderMessageDelete()
        {
            var post = GetPostWithMessages();

            foreach (var m in post.Messages)
            {
                Assert.IsFalse(MessageAction.CanUpdateMessageDatabase(m, m.CreatedBy, post));
            }
        }
Exemplo n.º 4
0
 public static void ReadResponse(Message message, ApplicationUser user, Post post, out StringBuilder errors)//Can be used for deleting a response or marking a response as read.
 {
     try
     {
         errors = new StringBuilder();
         if (!MessageAction.CanUpdateMessageDatabase(message, user, post))
         {
             errors.Append("Post ");
             return;
         }
         message.Read = true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public void RequiredMessageToDelete()
        {
            var post = GetPostWithMessages();

            Assert.IsFalse(MessageAction.CanUpdateMessageDatabase(null, post.Author, post));
        }