private MenuState TryToCreateReply()
        {
            var isPostExisting = this.postService.GetById(this.PostId) != null;

            if (!isPostExisting)
            {
                throw new UnexistingPostException();
            }

            var serviceModel = new ReplyServiceModel()
            {
                Content = string.Join(string.Empty, this.Reply.Content),
                Author  = this.Reply.Author,
                PostId  = this.PostId
            };


            var replyAddedSuccessfull = this.replyService.Create(serviceModel);

            if (!replyAddedSuccessfull)
            {
                this.Error = true;
                return(MenuState.Rerender);
            }

            return(MenuState.ReplyAdded);
        }
Пример #2
0
        public bool Create(ReplyServiceModel model)
        {
            using (var db = new ForumSystemDbContext())
            {
                var reply = new Reply()
                {
                    Content  = model.Content,
                    AuthorId = db.Users.First(u => u.Username == model.Author).Id,
                    PostId   = model.PostId
                };

                if (reply.IsValid())
                {
                    db.Replies.Add(reply);
                    db.SaveChanges();
                    return(true);
                }

                return(false);
            }
        }
Пример #3
0
 public ReplyViewModel(ReplyServiceModel model)
 {
     this.Content = this.GetLines(model.Content);
     this.Author  = model.Author;
 }