public ActionResult Vote(CastVote castVote) { Debug.WriteLine(castVote.Rating); int rating = castVote.Rating; int purchaseId = castVote.PurchaseId; if (purchaseId <= 0) { return(Json(new { Result = "Please provide a valid purchase id" })); } var votedOn = _pRepository.PurchaseHistory.FirstOrDefault(e => e.PurchaseID == purchaseId); if (votedOn == null) { return(Json(new { Result = "No purchase with that id" })); } if (votedOn.Rating > 0) { return(Json(new { Result = "You already voted on that item" })); } if (rating < 1 || rating > 5) { return(Json(new { Result = "Rating must be between 1 and 5" })); } votedOn.Rating = rating; _pRepository.SavePurchase(votedOn); //return Json(new { Result = rating, OK = true }); return(CastVote(rating, votedOn.ProductId)); }
public void ProcessOrder(Cart cart, ShippingDetails shippingDetails, string userId) { cart.CartEntries.ForEach(e => { var ph = new Purchase { PurchaseDate = DateTime.Now.ToString(), ShippingDetails = shippingDetails, ProductName = e.Product.Name, ProductCount = e.Quantity, UserId = userId, Price = e.Product.Discount > 0 ? Helpers.CalculateDiscount(e.Product.Price, e.Product.Discount) : e.Product.Price, ProductId = e.Product.ProductID, AffiliateId = e.Product.AffiliateId }; e.Product.Quantity -= e.Quantity; _pRepository.SaveProduct(e.Product); GlobalProductCache.UpdateProduct(e.Product); RealTimeSellData.ReplaceOrUpdateTrackedProduct(e.Product, e.Quantity); GlobalCache.GetCache().ClearCachedItem <ProductModel>(e.Product.ProductID); _prRepository.SavePurchase(ph); }); }