public async Task <IHttpActionResult> PostComment(int entryId, Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entry = _db.Entries.Include(x => x.User).First(x => x.Id == entryId); var userName = UserHelper.GetUserNameFromIdentity(User.Identity); var user = _userContext.GetUser(userName); comment.CreateDate = DateTime.Now; comment.Author = userName; comment.Entry = entry; comment.UserId = user.Id; _db.Comments.Add(comment); await _db.SaveChangesAsync(); var location = $"api/entry/{comment.Entry.Id}/comment/{comment.Id}"; _mailer.InformAboutComment(comment); return(Created(location, new CommentView { Id = comment.Id, Author = _userContext.GetUser(UserHelper.GetUserNameFromComplexUsername(comment.Author)).Name, CreateDate = comment.CreateDate.ToString("yyyy-MM-dd HH:mm"), Message = comment.Message })); }