/// <summary> /// Gets the user cart detail. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="hostingPath">The hosting path.</param> /// <returns></returns> public UserCartDetailModel GetUserCartDetail(long userId, string hostingPath) { UserCartDetailModel userCartDetailModel = new UserCartDetailModel(); try { List <UserCartDetailProductModel> productDetailModel = new List <UserCartDetailProductModel>(); SqlParameter[] parameter = new SqlParameter[1]; parameter[0] = new SqlParameter("USERID", userId); DataSet dataSet = DBHelper.GetDataTable("GETUSERCARTDETAIL", parameter, DBHelper.ParseString(settings.Value.AppDbContext)); if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count > 0) { DataTable dtProducts = dataSet.Tables[0]; DataTable dtImage = dataSet.Tables[1]; if (dtProducts != null && dtProducts.Rows.Count > 0) { double grandTotal = 0; foreach (DataRow item in dtProducts.Rows) { #region Image string image = string.Empty; DataRow[] drImage = dtImage.Select("ProductFK='" + DBHelper.ParseString(item["ProductId"]) + "' and ProductColorFK='" + DBHelper.ParseString(item["ProductColorFK"]) + "'"); if (drImage != null && drImage.Length > 0) { image = hostingPath + Constants.ProductImagesPath.Replace(@"\", "/") + "/" + DBHelper.ParseString(drImage[0]["Image"]); } #endregion productDetailModel.Add(new UserCartDetailProductModel { Price = DBHelper.ParseString(item["Price"]), Name = DBHelper.ParseString(item["Name"]), ProductId = DBHelper.ParseString(item["ProductId"]), Color = DBHelper.ParseString(item["Color"]), Image = image, ColorId = DBHelper.ParseString(item["ProductColorFK"]), Quantity = DBHelper.ParseString(item["Quantity"]), SubTotal = DBHelper.ParseString(item["SubTotalAmount"]), CartId = DBHelper.ParseString(item["UserCartId"]), }); grandTotal = grandTotal + DBHelper.ParseDouble(item["SubTotalAmount"]); } userCartDetailModel.productDetail = productDetailModel; userCartDetailModel.CartId = DBHelper.ParseString(dtProducts.Rows[0]["UserCartId"]); userCartDetailModel.UserId = DBHelper.ParseString(dtProducts.Rows[0]["UserFK"]); userCartDetailModel.GrandTotal = DBHelper.ParseString(grandTotal); userCartDetailModel.TotalItems = DBHelper.ParseString(dtProducts.Rows.Count); } } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); throw ex; } return(userCartDetailModel); }
/// <summary> /// Binds the check promocode return model. /// </summary> /// <param name="promoCode">The promo code.</param> /// <param name="cartDetailModel">The cart detail model.</param> /// <returns></returns> public static CheckPromocodeReturnModel BindCheckPromocodeReturnModel(PromoCode promoCode, UserCartDetailModel cartDetailModel) { CheckPromocodeReturnModel promocodeReturnModel = new CheckPromocodeReturnModel(); if (promoCode != null) { CheckPromocodeDetailModel promocodeDetailModel = new CheckPromocodeDetailModel(); promocodeDetailModel.PromocodeId = DBHelper.ParseString(promoCode.PromoCodeId); promocodeDetailModel.Name = DBHelper.ParseString(promoCode.Name); promocodeDetailModel.Promocode = DBHelper.ParseString(promoCode.Code); promocodeReturnModel.PromocodeModel = promocodeDetailModel; } if (cartDetailModel != null) { CheckPromocodeTotalModel totalModel = new CheckPromocodeTotalModel(); double total = 0; double discount = 0; foreach (var item in cartDetailModel.productDetail) { total = total + DBHelper.ParseDouble(item.SubTotal); } if (promoCode != null) { if (promoCode.Amount > 0) { discount = DBHelper.ParseDouble(promoCode.Amount); } else { discount = total * DBHelper.ParseDouble(promoCode.Percentage) / 100; } totalModel.TotalAmount = DBHelper.ParseString(total); total = total - discount; totalModel.DiscountAmount = DBHelper.ParseString(discount); totalModel.PayableAmount = DBHelper.ParseString(total); } promocodeReturnModel.AmountModel = totalModel; } return(promocodeReturnModel); }