public CommentResponseModel AddCommentToEstate(string userId, CommentRequestModel comment) { var user = this.users .GetById(userId); var newComment = new Comment() { Content = comment.Content, CreatedOn = DateTime.Now, EstateId = comment.RealEstateId, UserId = userId, User = user }; user.Comments.Add(newComment); this.users.SaveChanges(); var responseModel = new CommentResponseModel() { Content = newComment.Content, CreatedOn = newComment.CreatedOn, UserName = newComment.User.UserName }; return responseModel; }
public string AddCommentResponse(CommentResponseModel model) { if (ModelState.IsValid) { context.CommentResponse.Add(new CommentResponse() { CommentID = model.CommentID, Mail = model.Email, Name = model.Name, Text = model.Text, AddedDate = DateTime.Now, Image = "he" + new Random().Next(1, 5) + ".png" }); context.SaveChanges(); return("yes"); } return("no"); }