public bool UpdateTotalPrice(int cartID) { try { CartItemService cartItemService = new CartItemService(); VariantService variantService = new VariantService(); TblCart cart = GetByPrimaryKey(cartID); if (cart != null) { List <TblCartItem> cartItems = cartItemService.GetByCartID(cartID); decimal totalPrice = 0; if (cartItems != null && cartItems.Count > 0) { foreach (var item in cartItems) { Variant variant = variantService.GetByPrimaryKey(item.VariantID); if (variant != null) { totalPrice += (decimal)item.NumberVariant * (variant.VariantPrice != null ? variant.VariantPrice.Value : 0); } } } cart.TotalPrice = totalPrice; if (Update(cart)) { return(true); } } return(false); } catch (Exception ex) { LogService.WriteException(ex); return(false); } }
public string UpdateOptionOfProduct(int productID) { try { string result = ""; List <Variant> variants = new VariantService().GetByProductID(productID); string optionValue1 = "", optionValue2 = "", optionValue3 = ""; if (variants != null && variants.Count > 0) { foreach (var item in variants) { if (!string.IsNullOrEmpty(item.Option1)) { if (!optionValue1.Contains(item.Option1)) { optionValue1 += item.Option1 + ","; } } if (!string.IsNullOrEmpty(item.Option2)) { if (!optionValue2.Contains(item.Option2)) { optionValue2 += item.Option2 + ","; } } if (!string.IsNullOrEmpty(item.Option3)) { if (!optionValue3.Contains(item.Option3)) { optionValue3 += item.Option3 + ","; } } } optionValue1 = SString.RemoveElementAtBeginEnd(optionValue1, ","); optionValue2 = SString.RemoveElementAtBeginEnd(optionValue2, ","); optionValue3 = SString.RemoveElementAtBeginEnd(optionValue3, ","); } List <TblOption> options = GetByProductID(productID); if (options != null && options.Count > 0) { for (int i = 0; i < options.Count; i++) { if (i == 0) { options[i].OptionValue = optionValue1; } else if (i == 1) { options[i].OptionValue = optionValue2; } else if (i == 2) { options[i].OptionValue = optionValue3; } Update(options[i]); } } return(result); } catch (Exception ex) { LogService.WriteException(ex); return(""); } }