public ActionResult AllProducts(string search) { var products = db.Product.ToList(); var carts = db.Cart.ToList(); var cateogries = db.Category.ToList(); if (!string.IsNullOrEmpty(search)) { Category category = db.Category.Where(m => m.name == search).FirstOrDefault <Category>(); if (category != null) { products = db.Product.Where(m => m.category_id == category.id).ToList(); } if (category == null) { products = null; } } ProductCartModel productCartModel = new ProductCartModel { Cart = carts, Product = products }; return(View(productCartModel)); }
public LogicResult <int> AddToCart(ProductCartModel model) { if (Store.CartProducts.Any(m => m.Id == model.Id && m.UserId == model.UserId)) { return(LogicResult <int> .Failure(Validation.PrductExistInCart)); } if (model.Day <= 0) { return(LogicResult <int> .Failure(Validation.MustBeHigherThanZero)); } var priceDetail = new PriceDetail { Day = model.Day, Type = model.Type.ToEnum <ProductType>() }; var paymentDetailResult = _priceCalculationService.CalculatePrice(priceDetail); if (paymentDetailResult.IsSucceed) { model.PaymentDetail = paymentDetailResult.Data; Store.CartProducts.Add(model); return(LogicResult <int> .Succeed(DataCount)); } else { return(LogicResult <int> .Failure(Validation.UnSuccessfullOperation)); } }
public ActionResult Add(ProductCartModel model) { var result = _cartServiceFacade.AddToCart(model); if (result.IsSucceed) { return(Json(new { IsSucceed = result.IsSucceed, Count = result.Data }, JsonRequestBehavior.AllowGet)); } else { return(AjaxFailureResult(result)); } }
public ActionResult Details(ProductCartModel model) { try { if (Request.Form["btnContShopping"] != null) { return(RedirectToAction("Index", "Products", new { catID = model.Product.CatagoryID })); } else if (Request.Form["btnViewCart"] != null) { return(RedirectToAction("ViewCart", "Cart")); } else if (Request.Form["btnAddToCart"] != null) { // We can retrieve the product information from database List <CartModel> cartCookieList = new List <CartModel>(); CookieHelper <List <CartModel> > .GetValueFromCookie("cart", ref cartCookieList); var item = cartCookieList.Find(cart => cart.ProductID == model.Product.ProductID); int ProductQuantity = 0; if (item != null) { item.ProductQuantity += model.Cart.ProductQuantity; ProductQuantity = item.ProductQuantity; } else { model.Cart.ProductID = model.Product.ProductID; cartCookieList.Add(model.Cart); ProductQuantity = model.Cart.ProductQuantity; } model.Product = iBusinessShop.GetProduct(model.Product.ProductID.ToString()); CookieHelper <List <CartModel> > .SetValueToCookie("cart", cartCookieList, DateTime.MaxValue); model.Product.Status = ProductQuantity.ToString() + " items of " + model.Product.ShortDesc + " added to your cart."; } } catch (Exception) { throw; } return(View(model)); }
public void AddItem(ProductCartModel product, int quantity) { CartLine line = lineCollection .Where(g => g.Product.Id == product.Id) .FirstOrDefault(); if (line == null) { lineCollection.Add(new CartLine { Product = product, Quantity = quantity }); } else { line.Quantity += quantity; } }
public ActionResult Product(long?id) { if (Request.Cookies["Currency"] == null) { InitializeCurrency(); } if (id == null) { return(View("NotFound")); } var product = new ProductCartModel { Product = ProductDAO.Select(id.Value) }; product.Currency = currencyDAO.SelectBySymbol(Request.Cookies["Currency"]); product.ProductCurrency = ProductCurrencyDAO.SelectByProductAndCurrencyId(product.Product.Id, product.Currency.Id); ProductModel productModel = new ProductModel { Product = product }; if (User.Identity.Name != null) { productModel.Account = AccountDAO.SelectItemByLogin(User.Identity.Name); } try { productModel.Rate = RatingDAO.SelectAverageRateByProduct(productModel.Product.Product); } catch (InvalidOperationException) { productModel.Rate = 0.0; } if (User.Identity.Name != null) { if (OrderDetailsDAO.SelectItemsByAccountAndProduct(User.Identity.Name, id.Value).ToList().Count() > 0) { productModel.Bought = true; } } productModel.Ratings = AccountRatingDAO.SelectItemsByProduct(id.Value).Take(5).ToList(); return(View(productModel)); }
[HttpPut] //(productId), (customerId), (quantity) public IHttpActionResult IncreaseQuantity([FromBody] CartModel theCart) { designEntity = new online_tshirt_designingEntities(); CartModel cartModel = new CartModel(); ProductCartModel pc = new ProductCartModel(); Product matchesProduct = designEntity.products .Where(prod => prod.ProductId == theCart.ProductId)//Where statement .Select(x => new Product { ProductId = x.ProductId, ProductCode = x.ProductCode, ProductName = x.ProductName, ProductStyle = x.ProductStyle, ProductColor = x.ProductColor, ProductImg = x.ProductImg, ProductDisc = x.ProductDisc, ProductPrice = (int)x.ProductPrice, ProductSizeQuantM = (short)x.ProductSizeQuantM, ProductSizeQuantXL = (short)x.ProductSizeQuantXL, ProductSizeQuantXXL = (short)x.ProductSizeQuantXXL }) .FirstOrDefault(); //Sets the quantity cartModel.ProductQuantity = theCart.ProductQuantity; //Sets the price for selected individual product to be calculated cartModel.ProductQuantityPrice = matchesProduct.ProductPrice; // cartModel.TotalProductPrice += matchesProduct.ProductPrice; return(Ok(cartModel.ProductQuantityPrice)); }
public ActionResult Details(string prodID) { ProductCartModel ProductCart = new ProductCartModel(); CartModel cart = new CartModel(); ProductModel product = null; try { if (!string.IsNullOrEmpty(prodID)) { product = iBusinessShop.GetProduct(prodID); } ProductCart.Product = product; cart.ProductQuantity = 1; ProductCart.Cart = cart; } catch (Exception) { throw; } return(View(ProductCart)); }
[HttpPut] //(productId), (customerId), (quantity) public IHttpActionResult IncreaseQuantity([FromBody] CartModel theCart) { designEntity = new online_tshirt_designingEntities(); CartModel cartModel = new CartModel(); ProductCartModel pc = new ProductCartModel(); int updatedRecord = 0; var matchesProduct = designEntity.products //from statement .Join(designEntity.product_cart, //Source table of inner join prod => prod.ProductId, //Select the primarykey (the first part of the "on" clause in an sql "join" statement) cart => cart.ProductId, //Select the foreign key i.e on clause (prod, cart) => new { Prod = prod, Cart = cart } //Selection ) .Where(cart => (cart.Cart.ProductCartId == theCart.ProductCartId) && (cart.Cart.CustId == theCart.CustId))//Where statement .FirstOrDefault(); //Sets the quantity cartModel.ProductQuantity = theCart.ProductQuantity; //Sets the price for selected individual product to be calculated cartModel.ProductQuantityPrice = (int)matchesProduct.Prod.ProductPrice; //Change the entity object product_cart newProductCartEntry = matchesProduct.Cart; newProductCartEntry.ProductQuantity = cartModel.ProductQuantity; newProductCartEntry.ProductQuantityPrice = cartModel.ProductQuantityPrice; try { //Commits the changes and inserts the record //In Entity database updatedRecord = designEntity.SaveChanges(); } catch (Exception error) { System.Diagnostics.Debug.WriteLine("Error in Linq", error); } if (updatedRecord > 0) { //Return the product added in the cart var cart = from entProd in designEntity.products join entCart in designEntity.product_cart on entProd.ProductId equals entCart.ProductId where entCart.CustId == theCart.CustId select new { //Send entire product Obj entProd.ProductId, entProd.ProductCode, entProd.ProductCat, entProd.ProductName, entProd.ProductStyle, entProd.ProductColor, entProd.ProductImg, entProd.ProductDisc, entProd.ProductPrice, entProd.ProductSizeQuantM, entProd.ProductSizeQuantXL, entProd.ProductSizeQuantXXL, entCart.ProductCartId, entCart.ProductQuantity, entCart.ProductQuantityPrice, entCart.ProductSize }; //Calculates the price foreach (var item in cart) { //// Sets the quantity //cartModel.ProductQuantity = (short)item.ProductQuantity; ////Sets the quantity price //cartModel.ProductQuantityPrice = (int)item.ProductQuantityPrice; //Calcualtes the amount cartModel.TotalProductPrice += (int)item.ProductQuantityPrice; } return(Ok(new Tuple <IEnumerable <object>, double>(cart, cartModel.TotalProductPrice))); } return(NotFound()); }