public ActionResult FinalStep() { CartProductModel cartProducts = new CartProductModel(); cartProducts.HealthProducts = new List <Product>(); cartProducts.PharmacyProducts = new List <PharmacyProduct>(); cartProducts.Addresses = new List <Address>(); cartProducts.TotalItems = 0; cartProducts.TotalPrice = 0; int UserId = 0; if (Session["UserID"] == null) { return(RedirectToAction("Login", "Login")); } else { UserId = Convert.ToInt32(Session["UserID"]); } //get products from cart table var products = db.Carts.Where(c => c.userid == UserId).ToList(); foreach (var product in products) { cartProducts.TotalItems++; if (product.producttype == "healthproduct") { var prod = db.Products.Where(i => i.Product_Id == product.productid).FirstOrDefault(); cartProducts.HealthProducts.Add(prod); cartProducts.TotalPrice = cartProducts.TotalPrice + Convert.ToInt32(prod.Product_Price); } else if (product.producttype == "pharmacyproduct") { var prod = db.PharmacyProducts.Where(i => i.ProductId == product.productid).FirstOrDefault(); cartProducts.PharmacyProducts.Add(prod); cartProducts.TotalPrice = cartProducts.TotalPrice + Convert.ToInt32(prod.ProductPrice); } } //get adresses from adress table var addresses = db.Addresses.Where(c => c.UserId == UserId).ToList(); cartProducts.Addresses = addresses.Select(i => new Address() { AddressId = i.AddressId, AddressDoorNo = i.AddressDoorNo, AddressLine1 = i.AddressLine1, AddressLine2 = i.AddressLine2, LandMark = i.LandMark, PinCode = i.PinCode, UserId = i.UserId, Name = i.Name, City = i.City, State = i.State }).ToList();; Session["count"] = db.Carts.Where(c => c.userid == UserId).Count(); return(View("FinalStep", cartProducts)); }
public bool AddToCart(CartProductModel carts) { //if (int.Equals(carts.ProductId) || int.IsNullOrEmpty(carts.CartId)) //{ // return false; //} return(this.cartRepository.AddToCart(carts)); }
public bool AddToCart(CartProductModel cart) { if (cart.ProductId <= 0 || String.IsNullOrWhiteSpace(cart.CartId)) { return(false); } return(this.cartRepository.AddToCart(cart)); }
public IActionResult Post([FromBody] CartProductModel cart) { var result = this.cartService.AddToCart(cart); var response = new CartResultObject(result); response.Message = response.Result ? "Successfully added product to cart!" : "Something went wrong. Could not add product to cart."; return(this.StatusCode(201, response)); }
public IActionResult Post([FromBody] CartProductModel carts) { var result = this.cartService.AddToCart(carts); if (result) { return(this.StatusCode(201)); } else { return(this.BadRequest()); } }
public bool Edit(CartProductModel carts) { using (var connection = new MySqlConnection(this.connectionString)) { try { connection.Execute( "update carts set productid = @ProductId, cartid = @CartId where id = @Id", new { productid = @carts.ProductId, cartid = @carts.CartId }); } catch (Exception) { return(false); } } return(true); }
public bool AddToCart(CartProductModel carts) { using (var connection = new MySqlConnection(this.connectionString)) { try { connection.Execute( "insert into carts (productid, cartid) values(@productid, @cartid)", new { productid = @carts.ProductId, cartid = @carts.CartId }); } catch (Exception) { return(false); } } return(true); }
/// <summary> /// Новая запись /// </summary> /// <param name="item"></param> /// <returns></returns> public bool InsertCartProduct(CartProductModel item) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var data = db.cart_products .Where(s => s.id == item.Id); if (!data.Any()) { var newProduct = new cart_products() { id = item.Id, c_title = item.Title, c_desc = item.Desc, b_disabled = item.Disabled, c_price = item.PriceInfo, n_price = item.Price, c_price_old = item.PriceInfoPrev, n_price_old = item.PricePrev, f_site = _siteId, //n_product d_date_create = DateTime.Now, c_user_create = _currentUserId.ToString() }; var log = new LogModel() { PageId = item.Id, PageName = item.Title, Section = LogModule.Cart, Action = LogAction.insert, Comment = "Добавлен новый товар/услуга" }; InsertLog(log); tran.Commit(); return(true); } return(false); } } }
/// <summary> /// Новая запись /// </summary> /// <param name="item"></param> /// <returns></returns> public bool UpdateCartProduct(CartProductModel item) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var data = db.cart_products .Where(s => s.id == item.Id); if (data.Any()) { var product = data.Single(); product.c_title = item.Title; product.c_desc = item.Desc; product.b_disabled = item.Disabled; product.c_price = item.PriceInfo; product.n_price = item.Price; product.c_price_old = item.PriceInfoPrev; product.n_price_old = item.PricePrev; product.d_date_update = DateTime.Now; product.c_user_update = _currentUserId.ToString(); var log = new LogModel() { PageId = item.Id, PageName = item.Title, Section = LogModule.Cart, Action = LogAction.update, Comment = "Изменен товар/услуга" }; InsertLog(log); tran.Commit(); return(true); } return(false); } } }
public bool AddToCart(CartProductModel cart) { using (var connection = new MySqlConnection(this.connectionString)) { //var findMatching = connection.Query<CartProductModel>("SELECT quantity FROM Carts WHERE Carts.cartid = @userid AND Carts.productid = @productid", // new { userid = @cart.CartId, productid = @cart.ProductId }); //if (findMatching != null && findMatching.Any()) //{ // connection.Execute( // "UPDATE Carts SET quantity = @quantity WHERE cartid = @cartid AND productid = @productid", // new {cartid = @cart.CartId, productid = @cart.ProductId, quantity = @findMatching}); //} else //{ // try // { // connection.Execute( // "insert into Carts (productid, cartid) values(@productid, @cartid)", // new { productid = @cart.ProductId, cartid = @cart.CartId }); // } // catch (Exception) // { // return false; // } //} try { connection.Execute( "insert into Carts (productid, cartid) values(@productid, @cartid)", new { productid = @cart.ProductId, cartid = @cart.CartId }); } catch (Exception) { return(false); } } return(true); }
public CartModel GetOrderDetails(string userId) { var order = _orderRepository.GetCurrentOrder(userId); if (order == null) { return(new CartModel()); } var products = order.OrderProducts.Select(op => op.Product); var productListModel = new List <CartProductModel>(); foreach (var product in products) { var productModel = productListModel.FirstOrDefault(p => p.ProductId == product.ProductId); if (productModel == null) { productModel = new CartProductModel { ProductId = product.ProductId, ProductName = product.Name, ProductPrice = product.Price, Quantity = 1, RestaurantId = product.RestaurantId, RestaurantName = product.Restaurant.RestaurantName }; productListModel.Add(productModel); } else { productModel.Quantity++; } } return(new CartModel { Products = productListModel }); }
public bool InsertProduct(string orderId, CartProductModel product) { try { using (var connection = new SqlConnection(this.ConnectionString)) { var sql = "INSERT INTO OrderContent (OrderId, ProductId, Name, Price, Qty) " + "VALUES (@orderId, @productId, @name, @price, @qty)"; connection.Execute(sql, new { orderId, productId = product.ProductId, name = product.Name, price = product.Price, qty = product.Qty, }); } } catch (Exception) { return(false); } return(true); }
public object GetCartProduct(string openId = "") { CheckUserLogin(); var cartHelper = ServiceProvider.Instance <ICartService> .Create; var cart = cartHelper.GetCart(CurrentUser.Id); var productService = ServiceProvider.Instance <IProductService> .Create; var shopService = ServiceProvider.Instance <IShopService> .Create; var vshopService = ServiceProvider.Instance <IVShopService> .Create; var siteSetting = ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings(); var typeservice = ServiceProvider.Instance <ITypeService> .Create; List <CartProductModel> products = new List <CartProductModel>(); //会员折扣 decimal discount = 1.0M;//默认折扣为1(没有折扣) if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } decimal prodPrice = 0.0M; //优惠价格 var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList()); //限时购价格 foreach (var item in cart.Items) { var product = productService.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); SKUInfo sku = productService.GetSku(item.SkuId); if (sku == null) { continue; } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } ProductTypeInfo typeInfo = typeservice.GetType(product.TypeId); string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; if (sku != null) { var _tmp = new CartProductModel { CartItemId = item.Id.ToString(), SkuId = item.SkuId, Id = product.Id.ToString(), ImgUrl = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150), Name = product.ProductName, Price = prodPrice.ToString("F2"), Count = item.Quantity.ToString(), ShopId = shop.Id.ToString(), Size = sku.Size, Color = sku.Color, Version = sku.Version, VShopId = vshop == null ? "0" : vshop.Id.ToString(), ShopName = shop.ShopName, ShopLogo = vshop == null ? "" : Core.HimallIO.GetRomoteImagePath(vshop.Logo), Url = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId, IsValid = (product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) ? 1 : 0, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, AddTime = item.AddTime }; products.Add(_tmp); } } } products = products.OrderBy(item => item.ShopId).ThenByDescending(o => o.AddTime).ToList(); var cartShop = products.GroupBy(item => item.ShopId); var cartModel = new { Status = "OK", Data = cartShop }; return(Json(cartModel));//原api返回 }
private List <CartProductModel> PackageCartProducts(Himall.Entities.ShoppingCartInfo cart, decimal discount, bool isBranch = false) { List <CartProductModel> products = new List <CartProductModel>(); var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格 var groupCart = cart.Items.Where(item => item.ShopBranchId == 0).Select(c => { var cItem = new Himall.Entities.ShoppingCartItem(); var skuInfo = _iProductService.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId).ToList(); foreach (var item in cart.Items) { var product = ProductManagerApplication.GetProduct(item.ProductId); var shop = _iShopService.GetShop(product.ShopId); DTO.ShopBranch shopbranch = null; Entities.ShopBranchSkuInfo shopbranchsku = null; if (item.ShopBranchId > 0) { shopbranch = ShopBranchApplication.GetShopBranchById(item.ShopBranchId); shopbranchsku = ShopBranchApplication.GetSkusByIds(item.ShopBranchId, new List <string> { item.SkuId }).FirstOrDefault(); } if (null != shop) { var vshop = VshopApplication.GetVShopByShopId(shop.Id); var sku = ProductManagerApplication.GetSKU(item.SkuId); if (sku == null) { continue; } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); var prodPrice = sku.SalePrice; if (prod != null && !isBranch) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } #region 阶梯价--张宇枫 //阶梯价 if (product.IsOpenLadder) { var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity)); prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity); if (shop.IsSelf) { prodPrice = prodPrice * discount; } } #endregion var typeInfo = TypeApplication.GetProductType(product.TypeId); string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; if (product != null) { colorAlias = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias; } if (sku != null) { #region 正在参加限时抢购商品在购物车失效 TDO:ZYF var isLimit = false; //门店商品,在参加限时购,也可以正常购买 var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId); if (limit != null && !isBranch) { isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing; } #endregion var _tmp = new CartProductModel { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150), name = product.ProductName, price = prodPrice.ToString("F2"), count = item.Quantity, ShopId = shop.Id.ToString(), Size = sku.Size, Color = sku.Color, Version = sku.Version, VShopId = vshop == null ? "0" : vshop.Id.ToString(), ShopName = shop.ShopName, ShopLogo = vshop == null ? "" : Core.HimallIO.GetRomoteImagePath(vshop.StrLogo), Url = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId, ProductStatus = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()), status = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架; ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, AddTime = item.AddTime, shopBranchId = item.ShopBranchId, shopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName, ShopBranchLogo = null == shopbranch ? "" : Core.HimallIO.GetRomoteImagePath(shopbranch.ShopImages) }; products.Add(_tmp); } } } return(products); }
public object GetCartProduct(string openId = "") { CheckUserLogin(); List <CartProductModel> products = new List <CartProductModel>(); var cartItems = CartApplication.GetCartItems(CurrentUser.Id); var vshops = VshopApplication.GetVShopsByShopIds(cartItems.Select(p => p.Shop.Id)); foreach (var item in cartItems) { var sku = item.Sku; var product = item.Product; var shop = item.Shop; var vshop = vshops.FirstOrDefault(p => p.ShopId == shop.Id); var _tmp = new CartProductModel { CartItemId = item.ItemId.ToString(), SkuId = sku.Id, Id = product.Id.ToString(), ImgUrl = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150), Name = product.ProductName, Price = sku.SalePrice.ToString("F2"), MarketPrice = product.MarketPrice.ToString("F2"), Count = item.Quantity.ToString(), ShopId = shop.Id.ToString(), Size = sku.Size, Color = sku.Color, Version = sku.Version, VShopId = vshop == null ? "0" : vshop.Id.ToString(), ShopName = shop.ShopName, ShopLogo = vshop == null ? "" : Core.MallIO.GetRomoteImagePath(vshop.Logo), Url = Core.MallIO.GetRomoteImagePath("/m-IOS/product/detail/") + product.Id, ProductStatus = item.ShowStatus, ColorAlias = sku.ColorAlias, SizeAlias = sku.SizeAlias, VersionAlias = sku.VersionAlias, AddTime = item.AddTime, IsOpenLadder = product.IsOpenLadder, MaxBuyCount = product.MaxBuyCount, MinBath = ProductManagerApplication.GetProductLadderMinMath(product.Id), ActiveId = item.LimitId }; _tmp.IsValid = (_tmp.ProductStatus == 0) ? 0 : 1; products.Add(_tmp); } products = products.OrderBy(p => p.IsValid).ThenByDescending(item => item.AddTime).ToList(); var cartShop = products.GroupBy(item => item.ShopId); decimal prodPrice = 0.0M; //优惠价格 decimal discount = 1.0M; //默认折扣为1(没有折扣) if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } var productService = ServiceProvider.Instance <IProductService> .Create; var shopService = ServiceProvider.Instance <IShopService> .Create; var vshopService = ServiceProvider.Instance <IVShopService> .Create; var siteSetting = SiteSettingApplication.SiteSettings; var typeservice = ServiceProvider.Instance <ITypeService> .Create; var shopBranchService = ServiceProvider.Instance <IShopBranchService> .Create; var shopCartHelper = ServiceProvider.Instance <IBranchCartService> .Create; var branchcart = shopCartHelper.GetCart(CurrentUser.Id, 0); var branchProducts = PackageCartProducts(branchcart, prodPrice, discount, productService, shopService, shopBranchService, vshopService, typeservice, true); var sbProducts = branchProducts.OrderBy(p => p.Status).ThenByDescending(item => item.AddTime); var sbCartShop = sbProducts.GroupBy(item => item.ShopBranchId); return(Json(new { Shop = cartShop, ShopBranch = sbCartShop })); }
public ActionResult PlaceOrder(string paymentType) { int addressId = Convert.ToInt32(System.Web.HttpContext.Current.Session["SelectedAddress"]); CartProductModel cartProducts = new CartProductModel(); cartProducts.HealthProducts = new List <Product>(); cartProducts.PharmacyProducts = new List <PharmacyProduct>(); cartProducts.Addresses = new List <Address>(); cartProducts.TotalItems = 0; cartProducts.TotalPrice = 0; int UserId = 0; if (Session["UserID"] == null) { return(RedirectToAction("Login", "Login")); } else { UserId = Convert.ToInt32(Session["UserID"]); } //get products from cart table var products = db.Carts.Where(c => c.userid == UserId).ToList(); foreach (var product in products) { cartProducts.TotalItems++; if (product.producttype == "healthproduct") { var prod = db.Products.Where(i => i.Product_Id == product.productid).FirstOrDefault(); cartProducts.HealthProducts.Add(prod); cartProducts.TotalPrice = cartProducts.TotalPrice + Convert.ToInt32(prod.Product_Price); } else if (product.producttype == "pharmacyproduct") { var prod = db.PharmacyProducts.Where(i => i.ProductId == product.productid).FirstOrDefault(); cartProducts.PharmacyProducts.Add(prod); cartProducts.TotalPrice = cartProducts.TotalPrice + Convert.ToInt32(prod.ProductPrice); } } //get adresses from adress table var addresses = db.Addresses.Where(c => c.UserId == UserId).ToList(); cartProducts.Addresses = addresses.Select(i => new Address() { AddressId = i.AddressId, AddressDoorNo = i.AddressDoorNo, AddressLine1 = i.AddressLine1, AddressLine2 = i.AddressLine2, LandMark = i.LandMark, PinCode = i.PinCode, UserId = i.UserId, Name = i.Name, City = i.City, State = i.State }).ToList();; Session["count"] = db.Carts.Where(c => c.userid == UserId).Count(); if (paymentType == null) { ViewBag.message = "Select Payment Method"; return(View("FinalStep", cartProducts)); } else { if (paymentType == "cod") { orderPlacedProduct orderpp = new orderPlacedProduct(); string orderedhp_products = string.Empty; foreach (var item in cartProducts.HealthProducts) { if (string.IsNullOrEmpty(orderedhp_products)) { orderedhp_products = item.Product_Id.ToString(); } else { orderedhp_products = orderedhp_products + "|" + item.Product_Id.ToString(); } } string orderedpharm_products = string.Empty; foreach (var item in cartProducts.PharmacyProducts) { if (string.IsNullOrEmpty(orderedpharm_products)) { orderedpharm_products = item.ProductId.ToString(); } else { orderedpharm_products = orderedpharm_products + "|" + item.ProductId.ToString(); } } orderpp.orderPlacedHealthProducts = orderedhp_products; orderpp.orderPlacedPharmacyProducts = orderedpharm_products; db.orderPlacedProducts.Add(orderpp); db.SaveChanges(); int orderPlacedId = orderpp.orderPlacedId; Order order = new Order(); order.orderdate = DateTime.Now.Date; order.orderstatus = "In Progress"; order.userid = UserId; order.addressid = addressId; order.paymenttype = paymentType; if (paymentType == "online") { order.paymentstatus = "complete"; } else { order.paymentstatus = "In Progress"; } order.totalamount = cartProducts.TotalPrice; order.orderPlacedId = orderPlacedId; order.totalItems = cartProducts.TotalItems; db.Orders.Add(order); db.SaveChanges(); var cartproducts = db.Carts.Where(i => i.userid == UserId).ToList(); foreach (var item in cartproducts) { db.Carts.Remove(item); db.SaveChanges(); } } else { orderPlacedProduct orderpp = new orderPlacedProduct(); string orderedhp_products = string.Empty; foreach (var item in cartProducts.HealthProducts) { if (string.IsNullOrEmpty(orderedhp_products)) { orderedhp_products = item.Product_Id.ToString(); } else { orderedhp_products = orderedhp_products + "|" + item.Product_Id.ToString(); } } string orderedpharm_products = string.Empty; foreach (var item in cartProducts.PharmacyProducts) { if (string.IsNullOrEmpty(orderedpharm_products)) { orderedpharm_products = item.ProductId.ToString(); } else { orderedpharm_products = orderedpharm_products + "|" + item.ProductId.ToString(); } } orderpp.orderPlacedHealthProducts = orderedhp_products; orderpp.orderPlacedPharmacyProducts = orderedpharm_products; db.orderPlacedProducts.Add(orderpp); db.SaveChanges(); int orderPlacedId = orderpp.orderPlacedId; Order order = new Order(); order.orderdate = DateTime.Now.Date; order.orderstatus = "In Progress"; order.userid = UserId; order.addressid = addressId; order.paymenttype = paymentType; if (paymentType == "online") { order.paymentstatus = "complete"; } else { order.paymentstatus = "In Progress"; } order.totalamount = cartProducts.TotalPrice; order.orderPlacedId = orderPlacedId; order.totalItems = cartProducts.TotalItems; db.Orders.Add(order); db.SaveChanges(); var cartproducts = db.Carts.Where(i => i.userid == UserId).ToList(); foreach (var item in cartproducts) { db.Carts.Remove(item); db.SaveChanges(); } string outputHtml = paymentRequest(order); ViewBag.htmldata = outputHtml; return(View("PaymentPage")); } return(View("OrderPlaced")); } }