public HttpResponseMessage PostComment([FromBody] UserCommentModel userCommentModel) { string userId = User.Identity.UserId(); string userName = User.Identity.Name; IUserComment userComment = new UserComment { MemeId = userCommentModel.MemeId, DateCreated = DateTime.Now.ToUniversalTime(), UserId = userId, UserName = userName, Likes = 0, Dislikes = 0, Comment = userCommentModel.Comment != null ? userCommentModel.Comment.Length > 1000 ? userCommentModel.Comment.Substring(0, 1000) : userCommentModel.Comment : "" }; // Post comment (and record on time line) userComment = userCommentBusiness.PostUserComment(userComment); var response = Request.CreateResponse(HttpStatusCode.Created, userComment); response.Headers.Location = new Uri(Request.RequestUri, "/api/comments/" + userComment.Id); return(response); }
public ActionResult OrderComment(string str, string returnUrl) { ApplicationDbContext db = new ApplicationDbContext(); UserCommentModel commentModel = (UserCommentModel)Session["OrderDetails"]; foreach (MenuComment menuComment in commentModel.menuComments) { string value = Request["rating-" + menuComment.ItemID]; if (value.Equals("good")) { menuComment.Rating = 1; } else if (value.Equals("bad")) { menuComment.Rating = -1; } else { menuComment.Rating = 0; } menuComment.Text = Request["input-" + menuComment.ItemID]; db.MenuComments.Add(menuComment); } db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Add(int messageId, string commentText) { string userId = User.Identity.GetUserId(); UserCommentModel userCommentModel = new UserCommentModel(); userCommentModel.addComment(messageId, userId, commentText); return(RedirectToAction("Detail", "Message", new { id = messageId })); }
// “添加评论”功能,返回一张空白评论表,评论内容为对应订单的所有菜品 public ActionResult OrderComment(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MenuOrder menuOrder = db.MenuOrders.Find(id); UserCommentModel commentModel = CommentUtils.GetBlankCommentModel(menuOrder); Session["OrderDetails"] = commentModel; if (menuOrder == null) { return(HttpNotFound()); } return(View(commentModel)); }
public static UserCommentModel GetBlankCommentModel(MenuOrder menuOrder) { List <OrderItem> orderItems = OrderUtils.GetOrderDetails(menuOrder.OrderList); UserCommentModel commentModel = new UserCommentModel(); commentModel.menuOrder = menuOrder; commentModel.menuComments = new List <MenuComment>(); ApplicationDbContext db = new ApplicationDbContext(); foreach (OrderItem orderItem in orderItems) { MenuComment menuComment = new MenuComment(); menuComment.CommentDate = DateTime.Now; menuComment.ItemID = orderItem.ItemID; menuComment.MenuItem = db.MenuItems.FirstOrDefault(item => item.ID == orderItem.ItemID).Name; menuComment.OrderID = menuOrder.ID; menuComment.Username = menuOrder.Username; commentModel.menuComments.Add(menuComment); } return(commentModel); }
public IHttpActionResult Post(UserCommentModel model) { if (!ModelState.IsValid) { return(Response(new { Success = false })); } //save the comment var comment = new Comment() { AdditionalData = model.AdditionalData, CommentText = model.CommentText, EntityName = model.EntityName, EntityId = model.EntityId, DateCreated = DateTime.UtcNow, UserId = ApplicationContext.Current.CurrentUser.Id }; _customerCommentService.Insert(comment); var cModel = PrepareCommentPublicModel(comment, new[] { ApplicationContext.Current.CurrentUser }); return(Response(new { Success = true, Comment = cModel })); }