public CartViewModel GetCartCount(CartViewModel cartViewModel) { CartDataAccessService cartDataAccessService = new CartDataAccessService(); //CartViewModel viewModel = new CartViewModel(); // viewModel = cartDataAccessService.GetCartCount(cartViewModel); return cartDataAccessService.GetCartCount(cartViewModel); }
//GetCartCount(CartViewModel cartViewModel) public CartViewModel UpdateCartDetailLineItem(CartViewModel cartViewModel) { CartDataAccessService cartDataAccessService = new CartDataAccessService(); CartViewModel viewModel = new CartViewModel(); viewModel = cartDataAccessService.UpdateCartDetailLineItem(cartViewModel); return viewModel; }
public BaseViewModel() { Cart = new CartViewModel(); URLs = new URLCollection(); BreadCrumbs = new List<BreadCrumbViewModel>(); Theme = new Theme {Name = "Default", BaseURL = "localhost", TagLine = "Online Order Forms"}; }
// GET: /Carts/Details/5 public ActionResult AddNewProductCartDetailLineItem(FormCollection postedFormData) { // Retrieve the album from the database // var addedAlbum = storeDB.Albums.Single(album => album.AlbumId == id); // Add it to the shopping cart CartApplicationService cartApplicationService = new CartApplicationService(); CartViewModel cartViewModel = new CartViewModel(); var Cart = ShoppingCartActions.GetCart(); double subtotal = 99; cartViewModel.Cart.CartID = Cart.ShoppingCartId; cartViewModel.Cart.ProductID = Convert.ToInt32(postedFormData["ProductID"]); cartViewModel.Cart.ProductName = Convert.ToString(postedFormData["ProductName"]); // if (HiLToysBusinessServices.Utilities.IsNumeric((postedFormData["Quantity"])) == true) cartViewModel.Cart.Quantity = Convert.ToInt32(postedFormData["Quantity"]); // if (HiLToysBusinessServices.Utilities.ToDecimal((postedFormData["UnitPrice"])) == true) cartViewModel.Cart.UnitPrice = Convert.ToDouble(postedFormData["UnitPrice"]); // if (HiLToysBusinessServices.Utilities.ToDouble((postedFormData["SubTotal"])) == true) //cartViewModel.Cart.SubTotal = Convert.ToDouble(postedFormData["SubTotal"]); cartViewModel.Cart.SubTotal = subtotal; cartViewModel = cartApplicationService.AddCartDetailLineItem(cartViewModel); Session["payment_amt"] = cartViewModel.Cart.CartTotal; return Json(new { ReturnStatus = cartViewModel.ReturnStatus, viewModel = cartViewModel, //ValidationErrors = cartViewModel.ValidationErrors, //MessageBoxView = Helpers.MvcHelpers.RenderPartialView(this, "_MessageBox", cartViewModel), }); }
public CartViewModel GetCarts(string CartID) { CartDataAccessService cartDataAccessService = new CartDataAccessService(); CartViewModel viewModel = new CartViewModel(); viewModel.Cart.CartID = CartID; viewModel = cartDataAccessService.GetCarts(viewModel); return viewModel; }
public async Task <IActionResult> Index() { ViewBag.Title = "Cart"; ViewBag.Header = "Cart"; CartWithCustomerInfo cartWithCustomerInfo = await _serviceWrapper.GetCartAsync(ViewBag.CustomerId); var mapper = _config.CreateMapper(); var viewModel = new CartViewModel { Customer = cartWithCustomerInfo.Customer, CartRecords = mapper.Map <IList <CartRecordViewModel> >(cartWithCustomerInfo.CartRecords) }; return(View(viewModel)); }
public ActionResult StartCheckout() { var response = CartManager.GetCart(CommerceUserContext.Current.UserId, true); var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (!Context.PageMode.IsExperienceEditor && (cart.Lines == null || !cart.Lines.Any())) { #warning Remove hardcoded URL var cartPageUrl = "/shoppingcart"; return(Redirect(cartPageUrl)); } var cartViewModel = new CartViewModel(cart); return(View(cartViewModel)); }
public async Task <IActionResult> CreateWithoutRedirect(string type, int id) { CartViewModel cartVm = await _service.GetCartFromSessionAsync(HttpContext, SESSION_KEY); if (!cartVm.Items.Any(i => i.Category == type && i.ItemID == id)) { CartItemViewModel cartItemVm = await _service.CreateCartItemAsync(type, id); cartVm.AddItem(cartItemVm); } cartVm = await MergeCartsIfLogedIn(cartVm); return(RedirectToAction("Index", "Wishlist")); }
public ViewResult Index() { var items = _cart.GetItemsInCart(); _cart.CartItems = items; ViewBag.Product = items.Count; var cartViewModel = new CartViewModel() { Cart = _cart, TotalCartCost = _cart.GetTotalCartPrice() }; return(View(cartViewModel)); }
public ActionResult Checkout() { CartViewModel itemList = (CartViewModel)TempData["model"]; if (itemList == null) { itemList = cart.GetCart(); } decimal sum = itemList.Cart.Sum(x => x.Quantity * x.UnitPrice); decimal sumTax = sum + ((decimal)0.05 * sum); ViewData["Total"] = sum; ViewData["Total With Tax"] = sumTax; return(View(itemList)); }
public IActionResult myCart(CartViewModel data, string email) { try { email = User.Identity.Name; var list = _cartsService.GetCart(data, email); return(View(list)); } catch (Exception) { return(RedirectToAction("Error", "home")); } }
public IActionResult Index(int customerId) { ViewBag.Title = "Cart"; ViewBag.Header = "Cart"; var cartItems = _shoppingCartRepo.GetShoppingCartRecords(customerId); var customer = _customerRepo.Find(customerId); var mapper = _config.CreateMapper(); var viewModel = new CartViewModel { Customer = customer, CartRecords = mapper.Map <IList <CartRecordViewModel> >(cartItems) }; return(View(viewModel)); }
public async Task <IActionResult> Preview() { ApplicationUser currentUser = await _userManager.GetUserAsync(HttpContext.User); CartViewModel model = new CartViewModel( (await _repository.GetItemsFromCart(currentUser.Id)) .Select(i => new CartItemViewModel() { Id = i.Id, Name = i.Name, Price = i.Price }).ToList()); return(View(model)); }
public IActionResult AddItemToCart(CartViewModel cartViewModel) { // Details for this method are in the ./Services/CartService.cs _cartService.AddToCart(cartViewModel); if (cartViewModel.CategorySlug == "all-categories" && cartViewModel.BrandSlug == "all-brands") { return(RedirectToAction("Index", "Product", new { category_slug = "", brand_slug = "", page = cartViewModel.Page == "1" ? "" : cartViewModel.Page })); } else { return(RedirectToAction("Index", "Product", new { category_slug = cartViewModel.CategorySlug, brand_slug = cartViewModel.BrandSlug, page = cartViewModel.Page == "1" ? null : cartViewModel.Page })); } }
public JsonResult IncrementProduct(int productId) { //Init cart list List <CartViewModel> cart = Session["cart"] as List <CartViewModel>; //Get CartViewModel form the list CartViewModel model = cart.FirstOrDefault(x => x.ProductId == productId); //Increment quantity model.Quantity++; //Store needed data var result = new { qty = model.Quantity, price = model.Price }; //Return json with data return(Json(result, JsonRequestBehavior.AllowGet)); }
private bool CheckForStockOnItems(CartViewModel model) { Order Basket = model.CurrentOrder; SystemOperationResult result = MTApp.CheckForStockOnItems(Basket); if (result.Success) { return(true); } else { this.FlashFailure(result.Message); return(false); } }
public ViewResult CheckOut() { CartViewModel cartViewModel = GetCart(); Session.Clear(); string userId = User.Identity.GetUserId <string>(); List <CartLine> cartLines = cartViewModel.CartLineViewModels.Select(c => new CartLine() { ProductId = c.ProductId, Quantity = c.Quantity, TotalPrice = c.TotalPrice }).ToList(); businessLayer.SaveOrder(cartLines, userId); TempData["message"] = string.Format("Your order was successfully registered"); return(View("DisplayCart", GetCart())); }
public void AddToCart(Album album) { CartViewModel cart = new CartViewModel { AlbumId = album.AlbumId, GenreId = album.GenreId, ArtistId = album.ArtistId, Title = album.Title, Price = album.Price, CartId = ShoppingCartId }; var response = RequestHelper.Post(ShoppingCartAPI.AddToCartURL, cart); Console.WriteLine("AddToCart response: " + response); }
public RedirectToRouteResult List(OrderViewModel order) { CartViewModel model = cart.GetCart(order.SelectedProduct.ProductID); //Assign the quantity of the selected product to the quantity of the added product //____________________________________________________________ model.AddedProduct.Quantity = order.SelectedProduct.Quantity; //Call the method AddtoCart //_________________________________ cart.AddToCart(model); //Assign model to the TempData //__________________________________________ TempData["cart"] = model; return(RedirectToAction("List", "Cart")); }
public async Task <IActionResult> ProcessOrder() { ClearCartInSession(); var cartItems = GetCartInSession(); var cartViewModel = new CartViewModel(); cartViewModel.CartItemsAdded = cartItems; await SendOnlyBus.SendAsync(new ProcessOrder() { UserName = USER }, ORDERSAGASERVICENAME); return(View("Index", cartViewModel)); }
public List <CartViewModel> GetCartlist(string SessionId, ApplicationUser user) { List <CartViewModel> cartList = new List <CartViewModel>(); using (var db = new ApplicationDbContext()) { if (user != null) { var userCarts = db.UserCarts.Where(wl => wl.UserId == user.Id).ToList(); foreach (var p in userCarts) { CartViewModel viewModel = new CartViewModel(); viewModel.Id = p.Id; viewModel.ProductId = p.ProductId; viewModel.ProductName = p.Product.Name; viewModel.Title = p.Product.Title; viewModel.ProductImage = p.Product.ThumbMainImageName; viewModel.CategoryName = p.Product.ProductCategory.Name; viewModel.Qty = p.Qty; viewModel.ShippingCharges = p.Product.StandardShippingCharges; // ThumbMainImagePath = "Images/" + p.Product.ProductCategory.Name + "/" + p.Product.ThumbMainImageName, // viewModel.MRPPerUnit = p.m, viewModel.DisPer = p.Product.DiscountPerUnitInPercent; viewModel.SalePrice = p.Product.SalePrice; cartList.Add(viewModel); } } else { var userCarts = db.UserCarts.Where(wl => wl.SessionId == SessionId).ToList(); foreach (var p in userCarts) { CartViewModel viewModel = new CartViewModel(); viewModel.Id = p.Id; viewModel.ProductName = p.Product.Name; viewModel.Title = p.Product.Title; viewModel.ProductImage = p.Product.ThumbMainImageName; viewModel.Qty = p.Qty; // ThumbMainImagePath = "Images/" + p.Product.ProductCategory.Name + "/" + p.Product.ThumbMainImageName, // viewModel.MRPPerUnit = p.m, viewModel.DisPer = p.Product.DiscountPerUnitInPercent; viewModel.SalePrice = p.Product.SalePrice; cartList.Add(viewModel); } } } return(cartList); }
public int MakeOrder(CartViewModel cartViewModel) { NorthwindSabahEntities db = new NorthwindSabahEntities(); using (var tran = db.Database.BeginTransaction()) { try { var order = new Order() { CustomerID = cartViewModel.CustomerID, EmployeeID = cartViewModel.EmployeeID, ShipVia = cartViewModel.ShipVia, Freight = cartViewModel.Freight, ShipAddress = cartViewModel.Address, RequiredDate = cartViewModel.RequiredDate.Date, OrderDate = cartViewModel.OrderDate }; db.Orders.Add(order); db.SaveChanges(); foreach (var item in cartViewModel.CartModel) { if (item.ProductID == 1) { throw new Exception("Bir hata olustu"); } db.Order_Details.Add(new Order_Detail() { OrderID = order.OrderID, ProductID = item.ProductID, UnitPrice = item.UnitPrice, Quantity = item.Quantity, Discount = item.Discount }); } db.SaveChanges(); tran.Commit(); return(order.OrderID); } catch (Exception ex) { tran.Rollback(); throw ex; } } }
public Order CreateOrder(OrderViewModel OrderModel, CartViewModel Cart, string UserName) { if (UserName != null) { var user = _userManager.FindByNameAsync(UserName).Result; using (var transaction = _context.Database.BeginTransaction()) { var order = new Order { Address = OrderModel.Address, Phone = OrderModel.Phone, User = user, Date = DateTime.Now }; _context.Orders.AddAsync(order); foreach (var(product_model, quantity) in Cart.Items) { var product = _context.Products.FirstOrDefault(p => p.Id == product_model.Id); if (product is null) { throw new InvalidOperationException($"Товар с id:{product_model.Id} в базе данных на найден!"); } var order_item = new OrderItem { Order = order, Price = product.Price, Quantity = quantity, Product = product }; _context.OrderItems.AddAsync(order_item); } _context.SaveChanges(); transaction.Commit(); return(order); } } else { throw new InvalidOperationException("Зарегистрируйтесь на сайте или войдите в личный кабинет"); } }
public async Task <Order> CreateOrder(string UserName, CartViewModel Cart, OrderViewModel OrderModel) { var user = await _UserManager.FindByNameAsync(UserName); if (user is null) { throw new InvalidOperationException($"Пользователь {UserName} не найден в БД"); } await using var transaction = await _db.Database.BeginTransactionAsync(); var order = new Order { Name = OrderModel.Name, Address = OrderModel.Address, Phone = OrderModel.Phone, User = user, Date = DateTime.Now, Items = new List <OrderItem>() }; foreach (var(product_model, quantity) in Cart.Items) { var product = await _db.Products.FindAsync(product_model.Id); if (product is null) { throw new InvalidOperationException($"Товар id:{product_model.Id} не найден в БД"); } var order_item = new OrderItem { Order = order, Price = product.Price, Quantity = quantity, Product = product }; order.Items.Add(order_item); } await _db.Orders.AddAsync(order); await _db.SaveChangesAsync(); await transaction.CommitAsync(); return(order); }
// GET: /Users/ShowCart public ActionResult ShowCart() { email = User.Identity.GetUserName(); var items = context.CartItems.Where(c => c.UserEmail == email && c.IsCheckedOut == false).ToList(); var cartTotal = context.CartItems.Where(c => c.UserEmail == email && c.IsCheckedOut == false).Select(c => c.Item.Price * c.Count).DefaultIfEmpty(0).Sum(); var cart = context.OrderCarts.SingleOrDefault(c => c.UserEmail == email && c.IsCheckedOut == false); var cartViewModel = new CartViewModel { CartItems = items, Cart = cart, CartTotal = cartTotal }; return(View("Cart", cartViewModel)); }
public IActionResult Index([FromServices] ICustomerRepo customerRepo) { ViewBag.Title = "Cart"; ViewBag.Header = "Cart"; IEnumerable <CartRecordWithProductInfo> cartItems = _shoppingCartRepo.GetShoppingCartRecords(ViewBag.CustomerId); var customer = customerRepo.Find(ViewBag.CustomerId); var mapper = _config.CreateMapper(); var viewModel = new CartViewModel { Customer = customer, CartRecords = mapper.Map <IList <CartRecordViewModel> >(cartItems) }; return(View(viewModel)); }
public async Task <IActionResult> CheckoutGet() { var cart = getCartFromCookie(); var selectedFlowers = await getFlowersByIdAsync(cart.Items.ToArray()); var data = new CartViewModel() { CartValue = selectedFlowers.Sum(p => (p.Amount * p.Price)), Flowers = selectedFlowers }; setCartCookie(JsonConvert.SerializeObject(cart)); return(PartialView("Checkout", data)); }
// GET: Cart public ActionResult Index() { var cartId = new Helpers.CartHelpers().GetCartId(); var vm = new CartViewModel(); using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions(cartId)) { var shoppingCartItems = usersShoppingCart.GetCartItems(); var cartItemsVM = Mapper.Map <List <CartItemViewModel> >(shoppingCartItems); vm.CartItems = cartItemsVM; vm.ItemsTotal = usersShoppingCart.GetCount(); vm.OrderTotal = usersShoppingCart.GetTotal(); } //var shoppingCartItems = db.ShoppingCartItems.Include(c => c.Product); return(View(vm)); }
public CartViewModel AddItem(CartViewModel cart, int productId, int quantity) { var existingItem = cart.Items.FirstOrDefault(p => p.ProductId == productId); if (existingItem != null) { existingItem.Quantity += quantity; } else { var product = repository.Products.FirstOrDefault(p => p.Id == productId); var itemViewModel = itemViewModelFactory.Invoke(quantity, product); cart.Items.Add(itemViewModel); } return(cart); }
public async Task<IActionResult> Index(int customerId, string returnUrl) { ViewBag.Title = "Cart"; ViewBag.Header = "Cart"; //ViewBag.ReturnUrl = Request.Path + Request.QueryString; ViewBag.ReturnUrl = returnUrl; var cartItems = await WebAPICalls.GetCart(customerId); var customer = await WebAPICalls.GetCustomer(customerId); var mapper = _config.CreateMapper(); var viewModel = new CartViewModel { Customer = customer, CartRecords = mapper.Map<IList<CartRecordViewModel>>(cartItems) }; return View(viewModel); }
public ActionResult UpdateQuanity(CartViewModel cartItems) { //boolean value to determn if a give value is over the stock quantity bool Limit = false; //determing if cart item quantity is greater than what is currently in stock and setting the item quantity //accordingly if (cartItems.CartProduct.CartItemQuantity > cartItems.CartProduct.InStockQuantity) { cartItems.CartProduct.CartItemQuantity = cartItems.CartProduct.InStockQuantity; Limit = true; } CartDAL.SingleCartItemUpdate(mapper.Map(cartItems.CartProduct)); //setting limit value to show error message return(RedirectToAction("MyCart", "Cart", new { Limit = Limit })); }
public ActionResult Details() { AppUser user = GetCurrentUser(); if (user == null) { return(View("_Error", new string[] { GetErrorMessage.NullUser })); } Cart cart = _cartRepository.GetCurrentCart(user); CartViewModel model = _mapper.Map <Cart, CartViewModel>(cart); model.TotalValue = _cartRepository.GetTotalValue(cart); return(View(model)); }
public CartViewModel GetCartProduct(ProductCategoryViewModel pc) { using (var db = new PetsPlanetDBContext()) { CartViewModel cvm = new CartViewModel(); var data = db.GetProductCart(pc.PC3_Id); foreach (var x in data) { cvm.PC3_Name = x.PC3_Name; cvm.VPQ_Qty = Convert.ToInt16(x.VPQ_Qty); cvm.Vendor_Price = Convert.ToInt16(x.Vendor_Price); cvm.ProImg_Path = x.ProImg_Path; } return(cvm); } }
public ActionResult ListItems() { var items = (from i in _context.Items join ib in _context.ItemCarts on i.Id equals ib.ItemId where ib.SessionId == Session.SessionID select new CartItemViewModel() { Item = i, Quantity = ib.Count }).ToArray(); var cartViewModel = new CartViewModel(); cartViewModel.Items = items; return(Json(cartViewModel, JsonRequestBehavior.AllowGet)); }
private void TransformCartItemToOrderItem(OrderViewModel order, CartViewModel cart) { foreach (var cartItem in cart.Items) { order.Items.Add( new OrderItemView { Color = cartItem.Color, Quantity = cartItem.Quantity, UnitPrice = cartItem.UnitPrice, TotalPrice = cartItem.TotalPrice, ProductId = cartItem.ProductId, Product = cartItem.Product }); } }
public bool UpdateQuantity(CartViewModel cartViewModel) { QuoteDetail qd = _Context.QuoteDetail.GetSingle(e => e.QuoteDetailID == cartViewModel.QuoteDetailID && e.ItemID == cartViewModel.ItemId); qd.Quantity = cartViewModel.Quantity; int QuoteID = (int)qd.QuoteID; _Context.QuoteDetail.SaveChanges(); //Updating Penworthy Updated Date Quote quote = _Context.Quote.GetSingle(a => a.QuoteID == QuoteID); quote.PenworthyUpdatedDate = System.DateTime.UtcNow; _Context.Quote.SaveChanges(); return(true); }
public ActionResult CartSummary() { List<HiLToysDataModel.Cart> products = new List<HiLToysDataModel.Cart>(); CartApplicationService cartApplicationService = new CartApplicationService(); CartViewModel cartViewModel = new CartViewModel(); var Cart = ShoppingCartActions.GetCart(); cartViewModel.Cart.CartID = Cart.ShoppingCartId; cartViewModel = cartApplicationService.GetCarts(Cart.ShoppingCartId); if (cartViewModel.Cart.CartTotal < 1) Session["payment_amt"] = null; else Session["payment_amt"] = cartViewModel.Cart.CartTotal; cartViewModel = cartApplicationService.GetCartCount(cartViewModel); ViewData["CartCount"] = cartViewModel.Cart.Count; return PartialView("CartSummary"); }
public async Task<IHttpActionResult> Get(long id) { var user = await _authRepository.FindUser(HttpContext.Current.User as ClaimsPrincipal); var entity = await _cartRepository.GetAsync(id); if (entity == null) { return NotFound(); } if (entity.UserId != user.Id) { return StatusCode(HttpStatusCode.Forbidden); } var viewModel = new CartViewModel(); viewModel.Create(entity); return Ok(viewModel); }
public CartViewModel AddCartDetailLineItem(CartViewModel cartViewModel) { CartDataAccessService cartDataAccessService = new CartDataAccessService(); CartViewModel incartViewModel = new CartViewModel(); CartViewModel incartViewModel2 = new CartViewModel(); List<String> returnMessage = new List<String>(); returnMessage.Add(cartViewModel.Cart.ProductName + " is added in the cart"); int count = 0; incartViewModel.ReturnStatus = true; Boolean returnMessageforAddtoCart = true; returnMessageforAddtoCart = cartDataAccessService.AddToCart(cartViewModel); if (returnMessageforAddtoCart != true) { returnMessage.Add(cartViewModel.Cart.ProductName + " is not added in the cart"); incartViewModel.ReturnStatus = false; } incartViewModel.ReturnMessage = returnMessage; incartViewModel2= cartDataAccessService.GetCartCount(cartViewModel); count = incartViewModel2.Cart.Count; incartViewModel.Cart.Count = count; return incartViewModel; }
public CartViewModel UpdateCartDetailLineItem(CartViewModel cartViewModel) { CartViewModel rtncartViewModel = new CartViewModel(); ShoppingCartId = cartViewModel.Cart.CartID; rtncartViewModel.ReturnStatus = false; var cartItem = storeDB.Carts.SingleOrDefault( c => c.CartID == ShoppingCartId && c.ProductID == cartViewModel.Cart.ProductID); if (cartItem != null) { int quantity = 0; quantity = cartViewModel.Cart.Quantity; storeDB.Database.ExecuteSqlCommand("update Carts set Quantity = @quantity WHERE CartID=@ShoppingCartId AND ProductID=@ProductID", new SqlParameter("@quantity", quantity), new SqlParameter("@ShoppingCartId", ShoppingCartId), new SqlParameter("@ProductID", cartViewModel.Cart.ProductID)); //cartItem.Quantity = cartViewModel.Cart.Quantity; storeDB.SaveChanges(); rtncartViewModel.ReturnStatus = true; } else { rtncartViewModel.ReturnStatus = false; } rtncartViewModel.Cart.CartTotal = GetTotal(); return rtncartViewModel; }
public ActionResult DeleteCartDetailLineItem(FormCollection postedFormData) { CartApplicationService cartApplicationService = new CartApplicationService(); CartViewModel cartViewModel = new CartViewModel(); var Cart = ShoppingCartActions.GetCart(); cartViewModel.Cart.CartID = Cart.ShoppingCartId; cartViewModel.Cart.ProductID = Convert.ToInt32(postedFormData["ProductID"]); cartViewModel.Cart.ProductName=Convert.ToString(postedFormData["productName"]); string rowIndex = Convert.ToString(postedFormData["RowIndex"]); cartViewModel.Cart.RecordId = Convert.ToString(postedFormData["RecordId"]); cartViewModel = cartApplicationService.DeleteCartDetailLineItem(cartViewModel); Session["payment_amt"] = cartViewModel.Cart.CartTotal; return Json(new { ReturnStatus = cartViewModel.ReturnStatus, viewModel = cartViewModel, TotalCartCounts = cartViewModel.Cart.Count, xtotal = cartViewModel.Cart.CartTotal, RowIndex = rowIndex, // ValidationErrors = cartViewModel.ValidationErrors, // MessageBoxView = Helpers.MvcHelpers.RenderPartialView(this, "_MessageBox", cartViewModel), }); //return RedirectToAction("Index"); }
public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg) { if (bSandbox) { pEndPointURL = pEndPointURL_SB; host = host_SB; } string returnURL = "http://ethiohilecomvctoysapp2017.apphb.com/Checkout/CheckoutReview"; string cancelURL = "http://ethiohilecomvctoysapp2017.apphb.com/Checkout/CheckoutCancel"; NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["RETURNURL"] = returnURL; encoder["CANCELURL"] = cancelURL; encoder["BRANDNAME"] = "HiLEco MVC Toys Sample Application 2015"; encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD"; // Get the Shopping Cart Products CartApplicationService cartApplicationService = new CartApplicationService(); var Cart = ShoppingCartActions.GetCart(); // string CartID = Cart.GetCartId(this.HttpContext); string CartID = ""; CartID = Cart.ShoppingCartId; CartViewModel cartViewModel = new CartViewModel(); cartViewModel=cartApplicationService.GetCarts(CartID); int i = 0; foreach (var item in cartViewModel.Carts) { if (item.CartID != "") { encoder["L_PAYMENTREQUEST_0_NAME" + i] = item.ProductName.ToString(); encoder["L_PAYMENTREQUEST_0_AMT" + i] = item.UnitPrice.ToString(); encoder["L_PAYMENTREQUEST_0_QTY" + i] = item.Quantity.ToString(); } i++; } string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token; retMsg = ECURL; return true; } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return false; } }
// // GET: /Carts/ public ActionResult Index() { CartApplicationService cartApplicationService = new CartApplicationService(); var Cart = ShoppingCartActions.GetCart(); string CartID = Cart.ShoppingCartId; CartViewModel cartViewModel = new CartViewModel(); cartViewModel = cartApplicationService.GetCarts(CartID); if (cartViewModel.Cart.CartTotal < 1) Session["payment_amt"] = null; else Session["payment_amt"] = cartViewModel.Cart.CartTotal; return View("Index", cartViewModel); }
public ActionResult ResetCartSummary() { CartApplicationService cartApplicationService = new CartApplicationService(); CartViewModel cartViewModel = new CartViewModel(); var Cart = ShoppingCartActions.GetCart(); cartViewModel.Cart.CartID = Cart.ShoppingCartId; cartViewModel = cartApplicationService.GetCartCount(cartViewModel); ViewData["CartCount"] = cartViewModel.Cart.Count; return PartialView("CartSummary"); }
public ActionResult UpdateCartDetailLineItem(FormCollection postedFormData) { CartApplicationService cartApplicationService = new CartApplicationService(); CartViewModel cartViewModel = new CartViewModel(); var Cart = ShoppingCartActions.GetCart(); cartViewModel.Cart.CartID = Cart.ShoppingCartId; cartViewModel.Cart.ProductID = Convert.ToInt32(postedFormData["ProductID"]); //if (HiLToysBusinessServices.Utilities.IsNumeric((postedFormData["Quantity"])) == true) cartViewModel.Cart.Quantity = Convert.ToInt32(postedFormData["Quantity"]); cartViewModel = cartApplicationService.UpdateCartDetailLineItem(cartViewModel); Session["payment_amt"]=cartViewModel.Cart.CartTotal; return Json(new { ReturnStatus = cartViewModel.ReturnStatus, viewModel = cartViewModel, xtotal=cartViewModel.Cart.CartTotal, //ValidationErrors = cartViewModel.ValidationErrors, // MessageBoxView = Helpers.MvcHelpers.RenderPartialView(this, "_MessageBox", cartViewModel), }); }
public async Task<IHttpActionResult> Post(CartItem entity) { var user = await _authRepository.FindUser(HttpContext.Current.User as ClaimsPrincipal); var cart = new CartItem { ProductId = entity.ProductId, Product = await _unitOfWork.Products.GetAsync(entity.ProductId), UserId = user.Id, User = user }; if (cart.Product == null) { return StatusCode(HttpStatusCode.BadRequest); } if (!ModelState.IsValid) { return BadRequest(ModelState); } _cartRepository.Add(cart); await _unitOfWork.CompleteAsync(); var viewModel = new CartViewModel(); viewModel.Create(cart); return CreatedAtRoute("DefaultApi", new { id = entity.Id }, viewModel); }
public async Task<IHttpActionResult> Delete(long id) { var user = await _authRepository.FindUser(HttpContext.Current.User as ClaimsPrincipal); var isAdmin = await _authRepository.IsAdmin(HttpContext.Current.User as ClaimsPrincipal); if (user == null) { return Unauthorized(); } var entity = await _cartRepository.GetAsync(id); if (entity == null) { return NotFound(); } if (user.Id != entity.UserId && !isAdmin) { return StatusCode(HttpStatusCode.Forbidden); } _cartRepository.Remove(entity); await _unitOfWork.CompleteAsync(); var viewModel = new CartViewModel(); viewModel.Create(entity); return Ok(viewModel); }
public CartViewModel DeleteCartDetailLineItem(CartViewModel cartViewModel) { CartViewModel rtncartViewModel = new CartViewModel(); string RecordId = ""; RecordId = cartViewModel.Cart.RecordId; ShoppingCartId = cartViewModel.Cart.CartID; rtncartViewModel.ReturnStatus = false; var cartItem = storeDB.Carts.Single( cart => cart.CartID == ShoppingCartId && cart.RecordId == cartViewModel.Cart.RecordId); // int itemCount = 0; if (cartItem != null) { storeDB.Database.ExecuteSqlCommand("DELETE FROM Carts WHERE CartID = @ShoppingCartId AND RecordId=@RecordId", new SqlParameter("@RecordId", RecordId), new SqlParameter("@ShoppingCartId", ShoppingCartId)); // Save changes storeDB.SaveChanges(); rtncartViewModel.ReturnStatus = true; } rtncartViewModel.Cart.CartTotal = GetTotal(); rtncartViewModel.Cart.Count = GetCount(); return rtncartViewModel; }
public Boolean AddToCart(CartViewModel cartViewModel) { Boolean added = true; int counter = 0; ShoppingCartId = cartViewModel.Cart.CartID; var cartItem = storeDB.Carts.SingleOrDefault( c => c.CartID == ShoppingCartId && c.ProductID == cartViewModel.Cart.ProductID); //var cartItem = storeDB.Database.SqlQuery<Cart>("SELECT* FROM Carts WHERE CartID=@ShoppingCartId AND ProductID=@ProductID", new SqlParameter("@ShoppingCartId", ShoppingCartId), new SqlParameter("@ProductID", cartViewModel.Cart.ProductID)).FirstOrDefault(); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new HiLToysDataModel.Cart() { CartID = ShoppingCartId, RecordId = Guid.NewGuid().ToString(), ProductID = cartViewModel.Cart.ProductID, ProductName = cartViewModel.Cart.ProductName, Quantity = cartViewModel.Cart.Quantity, UnitPrice = cartViewModel.Cart.UnitPrice, SubTotal = cartViewModel.Cart.SubTotal, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); // storeDB.Entry(cartItem).State = System.Data.Entity.EntityState.Modified; // string sql="INSERT INTO Carts(CartID,RecordId,ProductID,ProductName,Quantity,UnitPrice,SubTotal,Count,DateCreated)VALUES(@CartID,@RecordId,@ProductID,@ProductName,@Quantity,@UnitPrice,@SubTotal,@Count,@DateCreated)"; // List<SqlParameter> parameterlist=new List<SqlParameter>(); // parameterlist.Add(new SqlParameter("@CartID",ShoppingCartId)); // parameterlist.Add(new SqlParameter("@RecordId",Guid.NewGuid().ToString())); // parameterlist.Add(new SqlParameter("@ProductName",cartViewModel.Cart.ProductName)); // parameterlist.Add(new SqlParameter("@Quantity",cartViewModel.Cart.Quantity)); // parameterlist.Add(new SqlParameter("@UnitPrice",cartViewModel.Cart.UnitPrice)); // parameterlist.Add(new SqlParameter("@SubTotal",cartViewModel.Cart.SubTotal)); // parameterlist.Add(new SqlParameter("@Count",1)); // parameterlist.Add(new SqlParameter("@DateCreated", DateTime.Now)); // SqlParameter[] parameters=parameterlist.ToArray(); //storeDB.Database.ExecuteSqlCommand(sql,parameters); } else { // If the item does exist in the cart, then add one to the quantity int totqant = 0; int count = 0; count = cartItem.Count + 1; totqant = cartItem.Quantity + cartViewModel.Cart.Quantity; storeDB.Database.ExecuteSqlCommand("update Carts set Quantity = @qnt,Count=@count where ProductID =@Pid", new SqlParameter("@Pid", cartItem.ProductID), new SqlParameter("@qnt", totqant), new SqlParameter("@count", count)); } storeDB.SaveChanges(); counter = GetCount(); if (counter == cartViewModel.Cart.Count) added = false; return added; }
// public ActionResult GetCartCount(FormCollection postedFormData) { CartApplicationService cartApplicationService = new CartApplicationService(); CartViewModel cartViewModel = new CartViewModel(); var Cart = ShoppingCartActions.GetCart(); cartViewModel.Cart.CartID = Cart.ShoppingCartId; cartViewModel = cartApplicationService.GetCartCount(cartViewModel); return Json(new { TotalCatCount = cartViewModel.Cart.Count }); }
public CartViewModel GetCarts(CartViewModel cartViewModel) { CartViewModel rtncartViewModel = new CartViewModel(); ShoppingCartId = cartViewModel.Cart.CartID; rtncartViewModel.Cart.CartTotal = GetTotal(); rtncartViewModel.Cart.Count = GetCount(); rtncartViewModel.Carts = storeDB.Database.SqlQuery<HiLToysDataModel.Cart>("SELECT* FROM Carts WHERE CartID = @ShoppingCartId", new SqlParameter("@ShoppingCartId", ShoppingCartId)).ToList(); return rtncartViewModel; }
public CartViewModel GetCartCount(CartViewModel cartViewModel) { ShoppingCartId = cartViewModel.Cart.CartID; cartViewModel.Cart.Count = GetCount(); return cartViewModel; }
public CartViewModel DeleteCartDetailLineItemX(CartViewModel cartViewModel) { CartViewModel rtncartViewModel = new CartViewModel(); ShoppingCartId = cartViewModel.Cart.CartID; rtncartViewModel.ReturnStatus = false; var cartItem = storeDB.Carts.Single( cart => cart.CartID == ShoppingCartId && cart.RecordId == cartViewModel.Cart.RecordId); int itemCount = 0; if (cartItem != null) { if (cartItem.Count > 1) { cartItem.Count--; itemCount = cartItem.Count; } else { storeDB.Carts.Remove(cartItem); } // Save changes storeDB.SaveChanges(); rtncartViewModel.ReturnStatus = true; } rtncartViewModel.Cart.CartTotal = GetTotal(); rtncartViewModel.Cart.Count = GetCount(); return rtncartViewModel; }