public ICollection <ShoppingCartDetail> GetCartItems(int customerId) { var cartItems = new List <ShoppingCartDetail>(); using (var connection = OpenConnection()) { StringBuilder query = new StringBuilder(); query.Append("SELECT shoppingCartDetailsID,ShoppingCartDetails.beerID"); query.Append(",quantityOrdered,ShoppingCartDetails.shoppingCartID"); query.Append(",ShoppingCartDetails.[Created_date],Beer.beerName,Beer.[description]"); query.Append(",Beer.price,ShoppingCart.customerID,Brewery.[description] as brewery"); query.Append(" "); query.Append("FROM ShoppingCartDetails inner join Beer on ShoppingCartDetails.beerID = Beer.beerID "); query.Append(" inner join ShoppingCart on ShoppingCartDetails.shoppingCartID = ShoppingCart.shoppingCartID"); query.Append(" inner join Brewery on Brewery.breweryID = Beer.breweryID"); query.Append(" where customerID=@customerID"); var command = CreateCommand(query.ToString(), connection); command.Parameters.AddWithValue("@customerID", customerId); var dataReader = ExecuteCommandAsReader(command); if (dataReader.HasRows) { while (dataReader.Read()) { cartItems.Add(ShoppingCartDetail.CreateEntity(dataReader, true, true)); } } } return(cartItems); }
public ShoppingCartDetail GetItemFromShoppingCart(int shoppingCartID, int beerId) { ShoppingCartDetail cart = null; using (var connection = OpenConnection()) { StringBuilder query = new StringBuilder(); query.Append("SELECT shoppingCartDetailsID,beerID,quantityOrdered,shoppingCartID,Created_date "); query.Append("FROM ShoppingCartDetails"); query.Append(" where shoppingCartID=@shoppingCartID and beerId=@beerId"); var command = CreateCommand(query.ToString(), connection); command.Parameters.AddWithValue("@shoppingCartID", shoppingCartID); command.Parameters.AddWithValue("@beerId", beerId); var dataReader = ExecuteCommandAsReader(command); if (dataReader.HasRows) { cart = new ShoppingCartDetail(); while (dataReader.Read()) { cart = ShoppingCartDetail.CreateEntity(dataReader); } } } return(cart); }
public IActionResult ProcessCheckout(CheckoutModel model) { // get the selected provider IPaymentProvider provider = _pluginClassesService.GetPluginClasses <IPaymentProvider>() .Where(p => p.UniqueId().CompareTo(model.SelectedProviderId) == 0).FirstOrDefault(); if (provider == null) { throw new InvalidOperationException(Middleware.Constants.PaymentProviderNotFound); } ShoppingCartDetail cartDetails = _shoppingCartProvider.GetDetail(GetCartSummary().Id); UserSession session = GetUserSession(); if (_shoppingCartProvider.ConvertToOrder(cartDetails, session.UserID, out Order order)) { if (provider.Execute(HttpContext.Request, order, PaymentStatus.Unpaid, session, out string providerUrl)) { session.Tag = order.Id; return(Redirect(providerUrl)); } } return(RedirectToAction(nameof(Failed))); }
public IActionResult Checkout(int?shippingId) { CheckoutModel model = new CheckoutModel(GetModelData()); ShoppingCartDetail cartDetail = _shoppingCartProvider.GetDetail(GetCartSummary().Id); if (cartDetail.RequiresShipping && (!shippingId.HasValue || (shippingId.HasValue && shippingId.Value < 1))) { return(RedirectToAction(nameof(Shipping))); } if (!cartDetail.RequiresShipping) { model.Breadcrumbs.RemoveAt(2); } Address shippingAddress = _accountProvider.GetDeliveryAddress(GetUserSession().UserID, shippingId.Value); if (shippingAddress != null) { cartDetail.SetDeliveryAddress(shippingAddress); } PrepareCheckoutModel(model, cartDetail); return(View(model)); }
public void RemoveFromCart(IProduct product) { if (!SessionUser.UserLoggedIn()) { SessionUser.Current.CartItems.Remove( SessionUser.Current.CartItems.Where(x => x.Product.ProductID == product.ProductID).FirstOrDefault() ); } else { //Items.Remove(SessionUser.Current.CartItems.Where(x => x.Product.ProductID == product.ProductID).FirstOrDefault()); ECommerceEntities entities = new ECommerceEntities(); Customer customer = entities.Customer.Where(x => x.CustomerID == SessionUser.Current.CustomerID).FirstOrDefault(); if (customer != null) { ShoppingCart cart = entities.ShoppingCart.Where(x => x.ShoppingCartID == customer.ShoppingCartID).FirstOrDefault(); if (cart != null) { ShoppingCartDetail detail = entities.ShoppingCartDetail.Where(x => x.ShoppingCart.ShoppingCartID == cart.ShoppingCartID && x.ProductId == product.ProductID).FirstOrDefault(); if (detail != null) { entities.ShoppingCartDetail.Remove(detail); } } } entities.SaveChanges(); } }
public void AddShoppingCartDetail() { var cart = _shoppingCartService.GetById(1); var product1 = _productService.GetById(1); var product2 = _productService.GetById(2); ShoppingCartDetail cart1Product1 = new ShoppingCartDetail() { Product = product1, Quantity = 2, ShoppingCart = cart }; ShoppingCartDetail cart1Product2 = new ShoppingCartDetail() { Product = product2, Quantity = 2, ShoppingCart = cart }; List <ShoppingCartDetail> list = new List <ShoppingCartDetail>() { cart1Product1, cart1Product2 }; bool result = _cartDetailService.SaveShoppingCartDetail(list); Assert.AreNotEqual(false, result); }
public HttpResponseMessage AddProductToShoppingCart(ShoppingCartDetail shoppingCartDetail) { try { DataTable dt = new DataTable(); using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["MarketPlaceDB"].ConnectionString)) using (var cmd = new SqlCommand(SP_AddProductToShoppingCart, con)) using (var da = new SqlDataAdapter(cmd)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@transactionId", shoppingCartDetail.transactionId); cmd.Parameters.AddWithValue("@userId", shoppingCartDetail.userId); cmd.Parameters.AddWithValue("@productId", shoppingCartDetail.productId); cmd.Parameters.AddWithValue("@quantity", shoppingCartDetail.quantity); cmd.Parameters.AddWithValue("@productPrice", shoppingCartDetail.productPrice); da.Fill(dt); } return(Request.CreateResponse(HttpStatusCode.OK, dt)); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Couldnt Add the product")); } }
public int Insert(ShoppingCartDetail entity) { entity.CreateDate = DateTime.Now; db.ShoppingCartDetails.Add(entity); db.SaveChanges(); return(entity.ShoppingCartDetailID); }
public async Task <ActionResult> ModifyShoppingcart_partial(string deliverytype) { Session["selectedmenu"] = "ShoppingCart"; Session["deliverytype"] = deliverytype; ShoppingCartDetail shoppingCartDetail = new ShoppingCartDetail(); BindCombo(); if (Session["Shoppingcart"] != null) { var listshop = (List <ShoppingCartModel>)Session["Shoppingcart"]; shoppingCartDetail.listshoppingItems = listshop; shoppingCartDetail.CartTotal = decimal.Parse(Session["SumTotal"].ToString()); //decimal GrandTotal = decimal.Parse(Session["SumTotal"].ToString()); //if (deliverytype == "Delivery") //{ // GrandTotal = GrandTotal + dlvcharge; //} Session["GrandTotal"] = decimal.Parse(Session["SumTotal"].ToString()); shoppingCartDetail.GrandCartTotal = decimal.Parse(Session["GrandTotal"].ToString()); //Decimal dd = decimal.Parse(Session["SumTotal"].ToString()); //shoppingCartDetail.CartTotal = Convert.ToDecimal(Session["SumTotal"].ToString(), CultureInfo.InvariantCulture); shoppingCartDetail.NoofItems = listshop.Sum(item => item.Qty).ToString(); ViewBag.isempty = "N"; } if (shoppingCartDetail.listshoppingItems == null) { ViewBag.isempty = "Y"; } return(PartialView("_Shoppingcart", shoppingCartDetail)); }
public IEnumerable <ShoppingCartDetail> GetAccountCart(string Account) { var model = new List <ShoppingCartDetail>(); ShoppingCartRepository shoppingCartRepository = new ShoppingCartRepository(); ProductsRepository productsRepository = new ProductsRepository(); ProductImageRepository productImageRepository = new ProductImageRepository(); foreach (var item in shoppingCartRepository.GetByAccount(Account)) { var cart = new ShoppingCartDetail { Account = Account, Color = item.Color, ProductID = item.Product_ID, Name = productsRepository.GetByProduct_ID(item.Product_ID).Product_Name, ShoppingCartID = item.Shopping_Cart_ID, Quantity = item.Quantity, RowPrice = item.UnitPrice * item.Quantity, UnitPrice = item.UnitPrice, Size = item.size, imgurl = productImageRepository.GetByProduct_ID(item.Product_ID).FirstOrDefault(x => x.Image_Only == "YES").Image }; model.Add(cart); } return(model); }
public IActionResult RemoveItem([FromBody] ShoppingCartDetail detail) { shoppingCartService.Items = HttpContext.Session.ParseShoppingCartItemsFromSession(); shoppingCartService.Items.Remove(detail); HttpContext.Session.SetObjectAsJson(key: "ShoppingCartDetails", value: shoppingCartService.Items); return(new OkResult()); }
public IActionResult Delete(int productId) { ShoppingCartDetail cartDetails = _shoppingCartProvider.GetDetail(GetCartSummary().Id); cartDetails.Delete(productId); return(RedirectToAction(nameof(Index))); }
public static void updateShoppingCartDetail(this ShoppingCartDetail shoppingCartDetail, ShoppingCartDetailViewModel shoppingCartDetailVm) { shoppingCartDetail.ShoppingCartID = shoppingCartDetailVm.ShoppingCartID; shoppingCartDetail.ProductID = shoppingCartDetailVm.ProductID; shoppingCartDetail.Quantity = shoppingCartDetailVm.Quantity; shoppingCartDetail.Price = shoppingCartDetailVm.Price; shoppingCartDetail.PromotionID = shoppingCartDetailVm.PromotionID; }
public async Task <ActionResult> ModifyShoppingcart(string data) { var result = JsonConvert.DeserializeObject <ShoppingCartModel>(data); ShoppingCartDetail shoppingCartDetail = new ShoppingCartDetail(); var listshop = (List <ShoppingCartModel>)Session["Shoppingcart"]; var Finditem = listshop.Find(x => x.ItemName.Contains(result.ItemName)); int oldqty = Finditem.Qty; int newqty = Convert.ToInt32(result.Qty); string deliverytype = "Pickup"; if (Session["deliverytype"] != null) { deliverytype = Session["deliverytype"].ToString(); } Finditem.Qty = newqty; decimal dd = Convert.ToDecimal(result.Price); Finditem.ItemLinePrice = Finditem.Price * newqty; //Decimal dd = decimal.Parse(result.Price); //Finditem.ItemLinePrice = Convert.ToDecimal(result.Price, CultureInfo.InvariantCulture) * newqty; shoppingCartDetail.listshoppingItems = listshop; decimal total = listshop.Sum(item => item.ItemLinePrice); //decimal GrandTotal = total; //if (deliverytype == "Delivery") //{ // GrandTotal = GrandTotal + dlvcharge; //} Session["SumTotal"] = total; Session["GrandTotal"] = total; //Session["GrandTotal"] = GrandTotal; shoppingCartDetail.CartTotal = total; shoppingCartDetail.GrandCartTotal = total; shoppingCartDetail.NoofItems = listshop.Sum(item => item.Qty).ToString(); ViewBag.isempty = "N"; //return PartialView("Index", shoppingCartDetail); //return View("Index", shoppingCartDetail); return(PartialView("_Shoppingcart", shoppingCartDetail)); //shoppingCartDetail.listshoppingItems = myList; //shoppingCartDetail.CartTotal = Convert.ToDecimal(Session["SumTotal"].ToString()); //ViewBag.isempty = "N"; //ShoppingCartDetail shoppingCartDetail = new ShoppingCartDetail(); //shoppingCartDetail.listshoppingItems = //List<ShoppingCartModel> listshop = new List<ShoppingCartModel>(); //listshop = (List<ShoppingCartModel>)Session["Shoppingcart"]; //return Json("Hi"); }
public bool AddToCart(IProduct product, int numberOfItems) { try { var t = new CartItem(product, numberOfItems); if (!SessionUser.UserLoggedIn() && SessionUser.Current.CartItems.Where(x => x.Product.ProductID == product.ProductID).Any() == false) { SessionUser.Current.CartItems.Add(t); } else if (GetItems().Where(x => x.Product.ProductID == product.ProductID).Any() == false) { ECommerceEntities entities = new ECommerceEntities(); Customer customer = entities.Customer.Where(x => x.CustomerID == SessionUser.Current.CustomerID).FirstOrDefault(); if (customer != null) { ShoppingCart cart = entities.ShoppingCart.Where(x => x.ShoppingCartID == customer.ShoppingCartID).FirstOrDefault(); if (cart != null) { ShoppingCartDetail detail = entities.ShoppingCartDetail.Where(x => x.ShoppingCart.ShoppingCartID == cart.ShoppingCartID && x.ProductId == product.ProductID).FirstOrDefault(); if (detail != null) { //Product prod = entities.Product.Where(x => x.ProductID == product.ProductID).FirstOrDefault(); detail.ItemCount += numberOfItems; } else { ShoppingCartDetail newItem = new ShoppingCartDetail(); newItem.CreationTime = DateTime.Now; newItem.ItemCount = numberOfItems; newItem.ProductId = product.ProductID; newItem.ShoppingCartId = cart.ShoppingCartID; entities.ShoppingCartDetail.Add(newItem); } } } entities.SaveChanges(); } return(true); } catch (Exception) { return(false); throw; } }
public IActionResult Update(UpdateQuantityModel model) { ShoppingCartDetail cartDetails = _shoppingCartProvider.GetDetail(GetCartSummary().Id); ShoppingCartItem item = cartDetails.Items.Where(i => i.Id == model.ProductId).FirstOrDefault(); if (item != null) { cartDetails.Update(item.Id, model.Quantity); } return(RedirectToAction(nameof(Index))); }
public IActionResult Shipping() { ShoppingCartSummary cartSummary = GetCartSummary(); ShoppingCartDetail cartDetails = _shoppingCartProvider.GetDetail(cartSummary.Id); if (!cartDetails.RequiresShipping) { return(RedirectToAction(nameof(Checkout))); } ShippingModel model = new ShippingModel(GetModelData()); PrepareShippingAddressModel(in model, _accountProvider.GetDeliveryAddresses(GetUserSession().UserID)); return(View(model)); }
public ShoppingCartJSonMessageModel DeleteFromCart(int id) { ShoppingCartDetail sd = _shoppingCartDetails.FindByID(id); ShoppingCart spCrt = _shoppingCart.FindByID(sd.ShoppingCartID); if (sd != null) { int CartID = sd.ShoppingCartID; int SiteID = spCrt.SiteID; _shoppingCartDetails.Delete(sd); _unitOfWork.Commit(); var cartItems = _shoppingCartDetails.Find(s => s.ShoppingCartID == CartID); var result = new ShoppingCartJSonMessageModel(); result.Message = "Product has been removed from your shopping cart."; result.ItemCount = cartItems.Count().ToString(); if (System.Convert.ToInt32(result.ItemCount) > 0) { result.CartTotal = string.Format("{0:C}", cartItems.Sum(p => p.Price) - cartItems.Sum(p => p.PromoDiscount)); } if (cartItems.Count() > 0) { result.Id = id.ToString(); } else { result.Id = System.Convert.ToString(SiteID); // ((CurrentSiteSettings.IsSiteRunWithHTTPS) ? "https://" : "http://") + ((CurrentSiteSettings.IsRunWithWWW) ? "www." : "") + CurrentSiteSettings.CurrentSite.Alias; } cartItems = null; return(result); } else { return(null); } }
public static ShoppingCardGridModel Convert(this ShoppingCartDetail cartDetail) { var entity = new ShoppingCardGridModel { BeerId = cartDetail.beerID, BeerName = cartDetail.Beer.beerName, Brewery = cartDetail.Beer.brewery, Description = cartDetail.Beer.description, Price = cartDetail.Beer.price, ShoppingCardDetailId = cartDetail.shoppingCartDetailsID, ShoppingCardId = cartDetail.shoppingCartID, QuantityOrdered = cartDetail.quantityOrdered, TotalPrice = cartDetail.Beer.price * cartDetail.quantityOrdered }; return(entity); }
public static void AssignPromoInCart(PromoCode prow, ShoppingCartDetail cartDetails, ProductPricing pp) { decimal promodiscount = 0; if (prow == null) { cartDetails.PromoCode = string.Empty; cartDetails.PromoDiscount = 0; return; } if (prow != null && cartDetails != null && cartDetails.ShoppingCartID > 0) { if (cartDetails.ProductID == prow.ProductID && cartDetails.ProductPricing.NumberOfMonths == prow.NoOfMonths) { if (prow.Discount > 0) { if (prow.DiscountModeID == (int)DiscountMode.FLAT) { promodiscount = prow.Discount; if (!cartDetails.Product.isNoOfServerFree) { promodiscount = (prow.Discount * (cartDetails.NumberOfServers > 0 ? cartDetails.NumberOfServers : 1)); } } else if (prow.DiscountModeID == (int)DiscountMode.PERCENTAGE) { promodiscount = (pp.SalesPrice * prow.Discount) / 100; if (!cartDetails.Product.isNoOfServerFree) { promodiscount = (promodiscount * (cartDetails.NumberOfServers > 0 ? cartDetails.NumberOfServers : 1)); } } } cartDetails.PromoCode = prow.Code; cartDetails.PromoDiscount = promodiscount; } else { cartDetails.PromoCode = string.Empty; cartDetails.PromoDiscount = 0; } } }
public async Task <ActionResult> DeleteItem(string pitemname) { //var result = JsonConvert.DeserializeObject<ShoppingCartModel>(data); ShoppingCartDetail shoppingCartDetail = new ShoppingCartDetail(); var listshop = (List <ShoppingCartModel>)Session["Shoppingcart"]; var Finditem = listshop.Find(x => x.ItemName.Contains(pitemname)); listshop.Remove(Finditem); //shoppingCartDetail.listshoppingItems.Remove(Finditem); //listshop = shoppingCartDetail.listshoppingItems; shoppingCartDetail.listshoppingItems = listshop; decimal total = listshop.Sum(item => item.ItemLinePrice); decimal GrandTotal = decimal.Parse(Session["SumTotal"].ToString()); string deliverytype = "Pickup"; if (Session["deliverytype"] != null) { deliverytype = Session["deliverytype"].ToString(); } if (deliverytype == "Delivery") { GrandTotal = GrandTotal + 25; } Session["GrandTotal"] = GrandTotal; Session["SumTotal"] = total; Session["cartitemcount"] = listshop.Count; shoppingCartDetail.CartTotal = total; shoppingCartDetail.GrandCartTotal = GrandTotal; shoppingCartDetail.NoofItems = listshop.Sum(item => item.Qty).ToString(); ViewBag.isempty = "N"; await HeaderLoad(); BindCombo(); DisplayModel dt = new DisplayModel(); dt = await DisplayModelList1(); shoppingCartDetail.displayModel = dt; return(View("Index", shoppingCartDetail)); //return PartialView("_Shoppingcart", shoppingCartDetail); }
public void MoveSessionCartToDb() { if (SessionUser.UserLoggedIn()) { ECommerceEntities et = new ECommerceEntities(); Customer customer = et.Customer.Where(x => x.CustomerID == SessionUser.Current.CustomerID).FirstOrDefault(); if (customer != null) { List <ShoppingCartDetail> details = et.ShoppingCartDetail.Where(x => x.ShoppingCartId == customer.ShoppingCartID).ToList(); List <ShoppingCartDetail> newItems = new List <ShoppingCartDetail>(); foreach (ShoppingCartDetail detail in details) { ICartItem cartItem = SessionUser.Current.CartItems.Where(x => x.Product.ProductID == detail.ProductId).FirstOrDefault(); if (cartItem != null) { detail.ItemCount += cartItem.ItemCount; } } foreach (ICartItem item in SessionUser.Current.CartItems) { ShoppingCartDetail itemDetail = new ShoppingCartDetail(); itemDetail.CreationTime = DateTime.Now; itemDetail.ItemCount = item.ItemCount; itemDetail.ProductId = item.Product.ProductID; itemDetail.ShoppingCartId = customer.ShoppingCartID; newItems.Add(itemDetail); } foreach (ShoppingCartDetail detail in newItems) { et.ShoppingCartDetail.Add(detail); } et.SaveChanges(); SessionUser.Current.CartItems.Clear(); } } }
public async Task <ActionResult> Index() { Session["selectedmenu"] = "ShoppingCart"; ShoppingCartDetail shoppingCartDetail = new ShoppingCartDetail(); BindCombo(); DisplayModel dt = new DisplayModel(); dt = await DisplayModelList1(); shoppingCartDetail.displayModel = dt; if (Session["Shoppingcart"] != null) { var calgranttotal = decimal.Parse(Session["GrandTotal"].ToString()); if (Session["deliverytypemenu"] != null) { if (Convert.ToString(Session["deliverytypemenu"]) == "Delivery") { calgranttotal += 25; } } var listshop = (List <ShoppingCartModel>)Session["Shoppingcart"]; shoppingCartDetail.listshoppingItems = listshop; shoppingCartDetail.CartTotal = decimal.Parse(Session["SumTotal"].ToString()); shoppingCartDetail.GrandCartTotal = calgranttotal; //shoppingCartDetail.GrandCartTotal = decimal.Parse(Session["GrandTotal"].ToString()); if (Session["CustSelectedTime"] != null) { shoppingCartDetail.Time = Convert.ToString(Session["CustSelectedTime"]); } shoppingCartDetail.NoofItems = listshop.Sum(item => item.Qty).ToString(); shoppingCartDetail.pagename = "S"; ViewBag.isempty = "N"; } if (shoppingCartDetail.listshoppingItems == null) { ViewBag.isempty = "Y"; } return(View(shoppingCartDetail)); }
public IActionResult Index() { List <BasketItemModel> basketItems = new List <BasketItemModel>(); ShoppingCartSummary cartSummary = GetCartSummary(); BasketModel model; BaseModelData modelData = GetModelData(); if (cartSummary.Id != 0) { ShoppingCartDetail cartDetails = _shoppingCartProvider.GetDetail(cartSummary.Id); _stockProvider.GetStockAvailability(cartDetails.Items); foreach (ShoppingCartItem item in cartDetails.Items) { basketItems.Add(new BasketItemModel(GetModelData(), item.Id, item.Name, item.Description, item.Size, item.SKU, item.ItemCost, (int)item.ItemCount, item.StockAvailability > 500 ? "> 500" : item.StockAvailability.ToString(), item.ItemCount * item.ItemCost, false, item.Images[0])); } if (TempData.ContainsKey("VoucherError")) { ModelState.AddModelError(nameof(VoucherModel.Voucher), Languages.LanguageStrings.VoucherInvalid); TempData.Remove("VoucherError"); } modelData.ReplaceCartSummary(cartSummary); model = new BasketModel(modelData, basketItems, cartDetails.CouponCode, cartDetails.RequiresShipping, !String.IsNullOrEmpty(GetUserSession().UserEmail)); } else { modelData.ReplaceCartSummary(cartSummary); model = new BasketModel(modelData, new List <BasketItemModel>(), String.Empty, false, GetUserSession().UserID != 0); } return(View(model)); }
public ActionResult Edit([Bind(Include = "ShoppingCartDetailID,ShoppingCartID,ProductID,ProductName,UnitPrice,Quantity,PromotionPrice,CreateDate,CreateUser,ModifiedDate,ModifiedUser")] ShoppingCartDetail shoppingCartDetail) { var UserSession = (UserLogin)Session[TechDeviShopVs002.Common.CommonConstants.USER_SESSION]; if (ModelState.IsValid) { var _dal = new ShoppingCartDetailDAL(); shoppingCartDetail.ModifiedUser = UserSession.UserID; var _result = _dal.Update(shoppingCartDetail); if (_result) { return(RedirectToAction("Index", "ShoppingCartDetails")); } else { ModelState.AddModelError("", "Cập nhật chi tiết giỏ hàng ko thành công"); } } return(View(shoppingCartDetail)); }
public ActionResult AddProductToCart(string proVaId, int quantity) { try { var shoppingCart = GetOrSetShoppingCart(); var id = Guid.Parse(proVaId); var shoppingCartDetail = _shoppingCartDetailService.GetByProductIdAndCartShoppingCartId(id, shoppingCart.Id); var productVa = _productVariationService.GetById(id); if (shoppingCartDetail != null) { // update quantity and update day shoppingCartDetail.Quantity = shoppingCartDetail.Quantity + quantity; shoppingCartDetail.UpdatedDate = DateTime.Now; _shoppingCartDetailService.Update(shoppingCartDetail); } else { // Add new shopping cart detail var cartDetail = new ShoppingCartDetail { Id = Guid.NewGuid(), ShoppingCart_Id = shoppingCart.Id, ProductVariation_Id = id, Quantity = quantity, CreatedDate = DateTime.Now, IsActive = true, }; _shoppingCartDetailService.Insert(cartDetail); } return(RedirectToAction("Index", "Shop")); } catch { return(RedirectToAction("Erorr", "Home")); } }
public bool Update(ShoppingCartDetail entity) { try { var _scd = db.ShoppingCartDetails.Find(entity.ShoppingCartDetailID); _scd.ShoppingCartID = entity.ShoppingCartID; _scd.ProductID = entity.ProductID; _scd.ProductName = entity.ProductName; _scd.UnitPrice = entity.UnitPrice; _scd.Quantity = entity.Quantity; _scd.PromotionPrice = entity.PromotionPrice; _scd.ModifiedDate = DateTime.Now; _scd.ModifiedUser = entity.ModifiedUser; _scd.CreateDate = entity.CreateDate; _scd.CreateUser = entity.CreateUser; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public async Task <Unit> Handle(Execute request, CancellationToken cancellationToken) { var shoppingCart = new Models.ShoppingCart { CreationDate = request.CreationDate }; _context.ShoppingCart.Add(shoppingCart); var rows = await _context.SaveChangesAsync(); if (rows == 0) { throw new Exception("There was an error creating Shopping Cart"); } int id = shoppingCart.ShoppingCartId; foreach (var item in request.ProductsList) { var shoopingCartDetail = new ShoppingCartDetail { CreationDate = DateTime.Now, ShoppingCartId = id, SelectedProduct = item }; _context.ShoppingCartDetail.Add(shoopingCartDetail); } id = await _context.SaveChangesAsync(); if (id > 0) { return(Unit.Value); } throw new Exception("There was an error inserting Shopping Cart details"); }
// // GET: /Store/AddToCart/5 public ActionResult AddToCart(int?id, string type) { Furniture addedFurniture = new Furniture(); Floral addedFloral = new Floral(); if (Session["productId"] != null && Session["productType"] != null) { ShoppingCartDetail shoppingCartDetailModel = new ShoppingCartDetail(); if (Session["productType"].Equals("floral")) { int sessionStoredId = (int)Session["productId"]; addedFloral = storeDB.Florals .Single(Floral => Floral.FloralId == sessionStoredId); shoppingCartDetailModel.Name = addedFloral.Name; shoppingCartDetailModel.Price = addedFloral.Price; shoppingCartDetailModel.Type = type; shoppingCartDetailModel.Quantity = 1; shoppingCartDetailModel.RemainingItem = addedFloral.Quantity - 1; shoppingCartDetailsProductList.Add(shoppingCartDetailModel); } else if (Session["productType"].Equals("furniture")) { int sessionStoredId = (int)Session["productId"]; addedFurniture = storeDB.furnitures .Single(Furniture => Furniture.FurnitureId == sessionStoredId); shoppingCartDetailModel.Name = addedFurniture.Name; shoppingCartDetailModel.Price = addedFurniture.Price; shoppingCartDetailModel.Type = type; shoppingCartDetailModel.Quantity = 1; shoppingCartDetailsProductList.Add(shoppingCartDetailModel); } } else { Session["productId"] = id; Session["productType"] = type; } // var addedProduct = new object(); // product can be floral , furniture // Retrieve the album from the database if (type == "floral") { ShoppingCartDetail shoppingCartDetailModel = new ShoppingCartDetail(); addedFloral = storeDB.Florals .Single(Floral => Floral.FloralId == id); shoppingCartDetailModel.Name = addedFloral.Name; shoppingCartDetailModel.Price = addedFloral.Price; shoppingCartDetailModel.Type = type; shoppingCartDetailModel.Quantity = 1; shoppingCartDetailModel.RemainingItem = addedFloral.Quantity - 1; shoppingCartDetailsProductList.Add(shoppingCartDetailModel); } else if (type == "furniture") { ShoppingCartDetail shoppingCartDetailModel = new ShoppingCartDetail(); addedFurniture = storeDB.furnitures .Single(Furniture => Furniture.FurnitureId == id); shoppingCartDetailModel.Name = addedFurniture.Name; shoppingCartDetailModel.Price = addedFurniture.Price; shoppingCartDetailModel.Type = type; shoppingCartDetailModel.Quantity = 1; shoppingCartDetailsProductList.Add(shoppingCartDetailModel); } //// Add it to the shopping cart //var cart = ShoppingCart.GetCart(this.HttpContext); //cart.AddToCart(addedProduct); // Not two at a time // Go back to the main store page for more shopping // return RedirectToAction("Index") return(View("CartIndex", shoppingCartDetailsProductList)); }
protected override void Seed(DatabaseContext context) { #region Veritabanı oluşurken örnek verileri kaydet #region Kategoriler Category category1 = new Category() { Title = "Telefon" }; context.Category.Add(category1); Category category2 = new Category() { Title = "Bilgisayar" }; context.Category.Add(category2); context.SaveChanges(); var telefon = context.Category.FirstOrDefault(c => c.Id == 1); Category category3 = new Category() { Title = "Apple", Parent = telefon }; context.Category.Add(category3); Category category4 = new Category() { Title = "Beyaz Eşya" }; context.Category.Add(category4); Category category5 = new Category() { Title = "Mutfak Eşyaları" }; context.Category.Add(category5); Category category6 = new Category() { Title = "Motosiklet" }; context.Category.Add(category6); context.SaveChanges(); #endregion #region Ürünler var telefonCat = context.Category.FirstOrDefault(c => c.Id == 1); var apple = context.Category.FirstOrDefault(c => c.Id == 3); var bilgisayar = context.Category.FirstOrDefault(c => c.Id == 2); var beyazesya = context.Category.FirstOrDefault(c => c.Id == 4); var mutfakesyalari = context.Category.FirstOrDefault(c => c.Id == 5); var motosiklet = context.Category.FirstOrDefault(c => c.Id == 6); Product product1 = new Product() { Title = "IPhone 4s", Price = 999, Category = apple }; context.Product.Add(product1); Product product2 = new Product() { Title = "IPhone 5s", Price = 1999, Category = apple }; context.Product.Add(product2); Product product3 = new Product() { Title = "IPhone 6s", Price = 2599, Category = apple }; context.Product.Add(product3); Product product4 = new Product() { Title = "IPhone 7s", Price = 2999, Category = apple }; context.Product.Add(product4); Product product5 = new Product() { Title = "IPhone 8s", Price = 3333, Category = apple }; context.Product.Add(product5); Product product6 = new Product() { Title = "Vestel Venus", Price = 750, Category = telefonCat }; context.Product.Add(product6); Product product7 = new Product() { Title = "Asus nw978x", Price = 2999, Category = bilgisayar }; context.Product.Add(product7); Product product8 = new Product() { Title = "Lenovo l8xm8", Price = 3499, Category = bilgisayar }; context.Product.Add(product8); Product product9 = new Product() { Title = "Çamaşır Makinası", Price = 4878, Category = beyazesya }; context.Product.Add(product9); Product product10 = new Product() { Title = "HTC xyz", Price = 789, Category = telefonCat }; context.Product.Add(product10); Product product11 = new Product() { Title = "Tencere", Price = 4000, Category = mutfakesyalari }; context.Product.Add(product11); Product product12 = new Product() { Title = "Kask", Price = 1000, Category = motosiklet }; context.Product.Add(product12); Product product13 = new Product() { Title = "Dizlik", Price = 1500, Category = motosiklet }; context.Product.Add(product13); Product product14 = new Product() { Title = "Bot", Price = 2000, Category = motosiklet }; context.Product.Add(product14); context.SaveChanges(); #endregion #region Sepete ürün ekle #region Sepet1 ShoppingCart.Entities.Cart.ShoppingCart cart1 = new Entities.Cart.ShoppingCart() { }; context.ShoppingCart.Add(cart1); context.SaveChanges(); var cart1db = context.ShoppingCart.FirstOrDefault(x => x.Id == 1); var cartIphone4s = context.Product.FirstOrDefault(x => x.Title == "IPhone 4s"); var cartIphone5s = context.Product.FirstOrDefault(x => x.Title == "IPhone 5s"); var cartIphone6s = context.Product.FirstOrDefault(x => x.Title == "IPhone 6s"); var cartIphone7s = context.Product.FirstOrDefault(x => x.Title == "IPhone 7s"); var cartIphone8s = context.Product.FirstOrDefault(x => x.Title == "IPhone 8s"); var lenovoLaptop = context.Product.FirstOrDefault(x => x.Title == "Lenovo l8xm8"); var htcTelefon = context.Product.FirstOrDefault(x => x.Title == "HTC xyz"); ShoppingCartDetail cart1Product1 = new ShoppingCartDetail() { Product = cartIphone4s, Quantity = 2, ShoppingCart = cart1db }; ShoppingCartDetail cart1Product2 = new ShoppingCartDetail() { Product = cartIphone5s, Quantity = 2, ShoppingCart = cart1db }; ShoppingCartDetail cart1Product3 = new ShoppingCartDetail() { Product = cartIphone6s, Quantity = 3, ShoppingCart = cart1db }; ShoppingCartDetail cart1Product4 = new ShoppingCartDetail() { Product = cartIphone7s, Quantity = 1, ShoppingCart = cart1db }; ShoppingCartDetail cart1Product5 = new ShoppingCartDetail() { Product = cartIphone8s, Quantity = 1, ShoppingCart = cart1db }; ShoppingCartDetail cart1Product6 = new ShoppingCartDetail() { Product = lenovoLaptop, Quantity = 1, ShoppingCart = cart1db }; ShoppingCartDetail cart1Product7 = new ShoppingCartDetail() { Product = htcTelefon, Quantity = 1, ShoppingCart = cart1db }; context.ShoppingCartDetail.Add(cart1Product1); context.ShoppingCartDetail.Add(cart1Product2); context.ShoppingCartDetail.Add(cart1Product3); context.ShoppingCartDetail.Add(cart1Product4); context.ShoppingCartDetail.Add(cart1Product5); context.ShoppingCartDetail.Add(cart1Product6); context.ShoppingCartDetail.Add(cart1Product7); context.SaveChanges(); #endregion #region Sepet2 ShoppingCart.Entities.Cart.ShoppingCart cart2 = new Entities.Cart.ShoppingCart() { }; context.ShoppingCart.Add(cart2); context.SaveChanges(); var cart2db = context.ShoppingCart.FirstOrDefault(x => x.Id == 2); var tencere = context.Product.FirstOrDefault(x => x.Title == "Tencere"); ShoppingCartDetail cart2Product1 = new ShoppingCartDetail() { Product = tencere, Quantity = 2, ShoppingCart = cart2db }; context.ShoppingCartDetail.Add(cart2Product1); context.SaveChanges(); #endregion #region Sepet3 ShoppingCart.Entities.Cart.ShoppingCart cart3 = new Entities.Cart.ShoppingCart() { }; context.ShoppingCart.Add(cart3); context.SaveChanges(); var cart3db = context.ShoppingCart.FirstOrDefault(x => x.Id == 3); var kask = context.Product.FirstOrDefault(x => x.Title == "Kask"); var dizlik = context.Product.FirstOrDefault(x => x.Title == "Dizlik"); var bot = context.Product.FirstOrDefault(x => x.Title == "Bot"); ShoppingCartDetail cart3Product1 = new ShoppingCartDetail() { Product = kask, Quantity = 1, ShoppingCart = cart3db }; ShoppingCartDetail cart3Product2 = new ShoppingCartDetail() { Product = dizlik, Quantity = 1, ShoppingCart = cart3db }; ShoppingCartDetail cart3Product3 = new ShoppingCartDetail() { Product = bot, Quantity = 1, ShoppingCart = cart3db }; context.ShoppingCartDetail.Add(cart3Product1); context.ShoppingCartDetail.Add(cart3Product2); context.ShoppingCartDetail.Add(cart3Product3); context.SaveChanges(); #endregion #endregion #region İndirim Ekle #region İndirim 1 Campaign campaign1 = new Campaign() { DiscountValue = 20.0, ProductCount = 3, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign1); context.SaveChanges(); var appleCatForCampaign = context.Category.FirstOrDefault(c => c.Title == "Apple"); var dbCampaign1 = context.Campaign.FirstOrDefault(c => c.Id == 1); CampaignCategoryMapping campaignCategoryMapping1 = new CampaignCategoryMapping() { Category = appleCatForCampaign, Campaign = dbCampaign1 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping1); #endregion #region İndirim 2 Campaign campaign2 = new Campaign() { DiscountValue = 50.0, ProductCount = 5, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign2); context.SaveChanges(); var dbCampaign2 = context.Campaign.FirstOrDefault(c => c.Id == 2); CampaignCategoryMapping campaignCategoryMapping2 = new CampaignCategoryMapping() { Category = appleCatForCampaign, Campaign = dbCampaign2 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping2); #endregion #region İndirim 3 Campaign campaign3 = new Campaign() { DiscountValue = 5.0, ProductCount = 5, DiscountType = DiscountType.Amount }; context.Campaign.Add(campaign3); context.SaveChanges(); var dbCampaign3 = context.Campaign.FirstOrDefault(c => c.Id == 3); CampaignCategoryMapping campaignCategoryMapping3 = new CampaignCategoryMapping() { Category = appleCatForCampaign, Campaign = dbCampaign3 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping3); context.SaveChanges(); #endregion #region İndirim 4 Campaign campaign4 = new Campaign() { DiscountValue = 70, ProductCount = 25, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign4); context.SaveChanges(); var dbCampaign4 = context.Campaign.FirstOrDefault(c => c.Id == 4); CampaignCategoryMapping campaignCategoryMapping4 = new CampaignCategoryMapping() { Category = appleCatForCampaign, Campaign = dbCampaign4 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping4); context.SaveChanges(); #endregion #region İndirim 5 var beyazEsyaCatForCampaign = context.Category.FirstOrDefault(c => c.Title == "Beyaz Eşya"); Campaign campaign5 = new Campaign() { DiscountValue = 50, ProductCount = 1, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign5); context.SaveChanges(); var dbCampaign5 = context.Campaign.FirstOrDefault(c => c.Id == 5); CampaignCategoryMapping campaignCategoryMapping5 = new CampaignCategoryMapping() { Category = beyazEsyaCatForCampaign, Campaign = dbCampaign5 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping5); context.SaveChanges(); #endregion #region İndirim 6 Campaign campaign6 = new Campaign() { DiscountValue = 15, ProductCount = 5, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign6); context.SaveChanges(); var dbCampaign6 = context.Campaign.FirstOrDefault(c => c.Id == 6); var telefonCatForCampaign = context.Category.FirstOrDefault(c => c.Title == "Telefon"); CampaignCategoryMapping campaignCategoryMapping6 = new CampaignCategoryMapping() { Category = telefonCatForCampaign, Campaign = dbCampaign6 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping6); context.SaveChanges(); #endregion #region İndirim 7 Campaign campaign7 = new Campaign() { DiscountValue = 10, ProductCount = 2, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign7); context.SaveChanges(); var dbCampaign7 = context.Campaign.FirstOrDefault(c => c.Id == 7); var motosikletCatForCampaign = context.Category.FirstOrDefault(c => c.Title == "Motosiklet"); CampaignCategoryMapping campaignCategoryMapping7 = new CampaignCategoryMapping() { Category = motosikletCatForCampaign, Campaign = dbCampaign7 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping7); context.SaveChanges(); #endregion #region İndirim 8 Campaign campaign8 = new Campaign() { DiscountValue = 20, ProductCount = 2, DiscountType = DiscountType.Rate }; context.Campaign.Add(campaign8); context.SaveChanges(); var dbCampaign8 = context.Campaign.FirstOrDefault(c => c.Id == 8); CampaignCategoryMapping campaignCategoryMapping8 = new CampaignCategoryMapping() { Category = motosikletCatForCampaign, Campaign = dbCampaign8 }; context.CampaignCategoryMapping.Add(campaignCategoryMapping8); context.SaveChanges(); #endregion #endregion #region Kupon Ekle Coupon coupon = new Coupon() { DiscountType = DiscountType.Rate, MinAmount = 2000, DiscountValue = 10 }; context.Coupon.Add(coupon); context.SaveChanges(); #endregion #endregion }