public async Task <ActionResult> AddComment(RatingAppIG4Item data) { var comment = customerDA.GetComment(data.ShopId, CustomerId); if (comment != null) { comment.TypeRating = data.TypeRating; comment.Title = data.Title; comment.Comment = data.Comment; comment.DateCreated = DateTime.Now; customerDA.Save(); CaculateRating(data); return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet)); } List <Gallery_Picture> imgs = new List <Gallery_Picture>(); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; var img = await UploadImage(file); if (!img.Erros) { var picture = new Gallery_Picture { Type = !string.IsNullOrEmpty(Request["type"]) ? Convert.ToInt32(Request["type"]) : 0, Folder = img.Data.Folder, Name = img.Data.Name, DateCreated = DateTime.Now.TotalSeconds(), IsShow = true, Url = img.Data.Url, IsDeleted = false, }; imgs.Add(picture); } } var item = new CustomerRating { ShopId = data.ShopId, CustomerId = CustomerId, TypeRating = data.TypeRating, DateCreated = DateTime.Now, Gallery_Picture = imgs, Title = data.Title, Comment = data.Comment }; customerDA.AddComment(item); CaculateRating(data); customerDA.Save(); return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet)); }
private void CaculateRating(RatingAppIG4Item data) { var rating = customerDA.GetTotalRating(data.ShopId); var customer = customerDA.GetById(data.ShopId); if (customer != null) { customer.Ratings = rating.Sum(m => m.Quantity); var totalrating = rating.Sum(m => m.Quantity * m.TypeRating); if (customer.Ratings != 0) { customer.AvgRating = totalrating / customer.Ratings; } else { customer.AvgRating = 0; } customerDA.Save(); } }
private void CaculateRating(RatingAppIG4Item data) { var rating = _productDa.GetTotalRating(data.ProductId.Value); var product = _productDa.GetById(data.ProductId.Value); if (product != null) { product.Ratings = rating.Sum(m => m.Quantity); var totalrating = rating.Sum(m => m.Quantity * m.TypeRating); if (product.Ratings != 0) { product.AvgRating = totalrating / product.Ratings; } else { product.AvgRating = 0; } _productDa.Save(); } }