public void PreCalculate() { if (_items == null || _items.Count == 0) { throw new Exception("No item to pre-calculate"); } var id = Guid.Parse(Id); long cartTax = 0; long cartSubTotal = 0; if (_items != null && _items.Count >= 0) { cartSubTotal = _items.Sum(i => i.TotalPrice); } long cartDiscount = 0; var orderPromo = OrderPromotionServices.CalculateForDiscount(id); var orderPromotionId = Guid.Empty; if (orderPromo != null) { cartDiscount = orderPromo.DiscountAmount; orderPromotionId = orderPromo.Id; } ApplyChange(new ShoppingCartPromotionCalulatedForOrderDiscount(id, orderPromotionId)); var cartTotal = cartSubTotal - cartTax - cartDiscount - _voucherValue - _shippingFee; ApplyChange(new ShoppingCartPreCalculated(id, DateTime.Now, cartTax, cartDiscount, cartSubTotal, cartTotal)); }
private static void PreCalculateShoppingCart(Guid shoppingCartId, Guid productId, int productQuantity) { var hubContext = GlobalHost.ConnectionManager.GetHubContext <SystemNotificationHub>(); var msg = string.Empty; var pp = ProductPromotionServices.CalculateDiscount(productId, productQuantity); var ooDiscount = OrderPromotionServices.CalculateForDiscount(shoppingCartId); var ooShipping = OrderPromotionServices.CalculateForShipping(shoppingCartId); using (var db = new CoreEcommerceDbContext()) { if (pp != null) { msg += db.ContentLanguages.GetValue(pp.Id, "Description"); } if (ooDiscount != null) { msg += "<br>" + db.ContentLanguages.GetValue(ooDiscount.Id, "Description"); } if (ooShipping != null) { msg += "<br>" + db.ContentLanguages.GetValue(ooShipping.Id, "Description"); } } if (!string.IsNullOrEmpty(msg)) { hubContext.Clients.All.shoppingCartMessage(new NotificationMessage() { DataType = "ShoppingCart", DataJson = JsonConvert.SerializeObject(new { Id = shoppingCartId, ProductId = productId, ActionType = "PreCalculateShoppingCart", Message = msg }) }); } hubContext.Clients.All.shoppingCartMessage(new NotificationMessage() { DataType = "ShoppingCart", DataJson = JsonConvert.SerializeObject(new { Id = shoppingCartId, ActionType = "RefreshShoppingCart", Message = msg }) }); }