public JsonResult AddOrderEvaluationAndComment(int packMark, int deliveryMark, int serviceMark, long orderId, string productCommentsJSON) { if (packMark != 0 || deliveryMark != 0 || serviceMark == 0) { var info = new DTO.OrderComment(); info.UserId = CurrentUser.Id; info.PackMark = packMark; info.DeliveryMark = deliveryMark; info.ServiceMark = serviceMark; info.OrderId = orderId; TradeCommentApplication.Add(info); } var productComments = JsonConvert.DeserializeObject <List <ProductCommentsModel> >(productCommentsJSON); var list = new List <DTO.ProductComment>(); foreach (var productComment in productComments) { var model = new ProductComment(); model.ReviewDate = DateTime.Now; model.ReviewContent = productComment.content; model.UserId = CurrentUser.Id; model.UserName = CurrentUser.UserName; model.Email = CurrentUser.Email; model.SubOrderId = productComment.subOrderId; model.ReviewMark = productComment.star; if (productComment.proimages != null && productComment.proimages.Length > 0) { model.Images = new List <ProductCommentImage>(); foreach (var img in productComment.proimages) { var p = new ProductCommentImage(); p.CommentType = 0; //0代表默认的表示评论的图片 p.CommentImage = MoveImages(img, CurrentUser.Id); model.Images.Add(p); } } list.Add(model); } var comments = CommentApplication.GetProductEvaluationByOrderIdNew(orderId, CurrentUser.Id); foreach (var item in comments) { var addComment = productComments.FirstOrDefault(e => e.subOrderId == item.Id); if (addComment != null) { return(Json(new Result() { success = false, msg = "您已进行过评价!", status = -1 })); } } CommentApplication.Add(list); return(Json(new Result() { success = true, msg = "评价成功" })); }
void AddProductsComment(long orderId, IEnumerable <ProductCommentModel> productComments) { var list = new List <ProductComment>(); foreach (var productComment in productComments) { var model = new ProductComment(); model.ReviewDate = DateTime.Now; model.ReviewContent = productComment.Content; model.UserId = CurrentUser.Id; model.UserName = CurrentUser.UserName; model.Email = CurrentUser.Email; model.SubOrderId = productComment.OrderItemId; model.ReviewMark = productComment.Mark; model.ProductId = productComment.ProductId; if (productComment.Images != null && productComment.Images.Length > 0) { model.Images = new List <ProductCommentImage>(); foreach (var img in productComment.Images) { var p = new ProductCommentImage(); p.CommentType = 0;//0代表默认的表示评论的图片 p.CommentImage = MoveImages(img, CurrentUser.Id); model.Images.Add(p); } } else if (productComment.WXmediaId != null && productComment.WXmediaId.Length > 0) { model.Images = new List <ProductCommentImage>(); foreach (var img in productComment.WXmediaId) { var p = new ProductCommentImage(); p.CommentType = 0;//0代表默认的表示评论的图片 p.CommentImage = DownloadWxImage(img); if (!string.IsNullOrEmpty(p.CommentImage)) { model.Images.Add(p); } } } list.Add(model); } CommentApplication.Add(list); }