Exemplo n.º 1
0
        /// <summary>
        /// Checkout the basket using the default payment method.
        /// </summary>
        /// <returns>New basket.</returns>
        public IActionResult Checkout()
        {
            //This functionality is not implemented. It will just clear the basket.

            ShoppingCartModel updatedBasket = httpHelper.ClearBasket(apiBasket + put);

            TempData[tempkey] = JsonConvert.SerializeObject(updatedBasket);
            return(RedirectToAction(nameof(ProductsController.Home)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add an item to a basket.
        /// </summary>
        /// <param name="id">Id of the item to add.</param>
        /// <param name="redirectToHome">Whether to redirect to the home screen or the shopping cart window.</param>
        /// <returns>Redirects to the parent window.</returns>
        public IActionResult AddToBasket(Guid id, bool redirectToHome)
        {
            ShoppingCartModel updatedBasket = httpHelper.AddItemToBasket(apiBasket, id);

            TempData[tempkey] = JsonConvert.SerializeObject(updatedBasket);
            string destination = redirectToHome ? nameof(ProductsController.Home) : nameof(ProductsController.ShoppingCart);

            return(RedirectToAction(destination));
        }
Exemplo n.º 3
0
        public static string Generate(ShoppingCartModel shoppingCart)
        {
            var sb = new StringBuilder();

            sb.Append(@"<style>
                        .invoice {
                          box-shadow: 0 0 1in -0.25in rgba(0, 0, 0, 0.5);
                          padding:2mm;
                          margin: 0 auto;
                          width: 84mm;
                          background: #FFF;
                        }                          
                        p{
                          font-size: 2.7em;
                          color: #666;
                          line-height: 1.2em;
                        }                          
                        .info{
                          display: block;
                          margin-left: 0;
                        }
                        .title{
                          float: right;
                        }
                        .title p{text-align: right;} 
                        table{
                          width: 100%;
                          border-collapse: collapse;
                        }
                        .tabletitle{
                          font-size: .5em;
                          background: #EEE;
                        }
                        .item{width: 24mm;}
                        .itemtext{font-size: .8em;}
                    </style>");

            sb.Append(@"<div class='invoice'><div class='bot'><div class='table'><table>");
            sb.Append(@"<tr class='tabletitle'><td><h2>Item</h2></td><td><h2>Qty</h2></td><td><h2>Sub Total</h2></td></tr>");

            foreach (var product in shoppingCart.Products)
            {
                sb.Append($@"<tr class='service'>
                            <td class='tableitem'><p class='itemtext'>{product.Name}</p></td>
                            <td class='tableitem'><p class='itemtext'>{product.Count}</p></td>
                            <td class='tableitem'><p class='itemtext'>${product.TotalAmount}</p></td>
                          </tr>");
            }

            sb.Append($@"<tr class='tabletitle'>
                                    <td></td>
                                        <td><h2>Total</h2></td>
                                        <td><h2>${shoppingCart.GetTotalAmount()}</h2></td>
                                    </tr>");
            sb.Append(@"</table></div></div></div>");
            return(sb.ToString());
        }
Exemplo n.º 4
0
        // GET: Cart
        public ActionResult Index()

        {
            ViewBag.Tittle = "Giỏ Hàng";
            ShoppingCartModel model = new ShoppingCartModel();

            model.Cart = (ShopCart)Session["Cart"];
            return(View(model));
        }
Exemplo n.º 5
0
        public bool ProcessOrder(AddressModel address, ContactModel contact, ShoppingCartModel cart, int paymentId, int deliveryId, string comment)
        {
            var dbAddress      = GetAddressByStreet(address);
            var dbContact      = GetContactBySocialSecurityNumber(dbAddress, contact);
            var dbPaymentType  = GetPaymentTypeById(paymentId);
            var dbDeliveryType = GetDeliveryTypeById(deliveryId);

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    var order = new Order
                    {
                        Address      = dbContact.Address,
                        Contact      = dbContact,
                        OrderNumber  = System.Guid.NewGuid().ToString(),
                        DeliveryType = dbDeliveryType,
                        PaymentType  = dbPaymentType,
                        TotalPrice   = cart.GetCartTotal(),
                        OrderDate    = DateTime.Now,
                        Comment      = comment,
                    };
                    context.Orders.Add(order);
                    context.SaveChanges();

                    foreach (var item in cart.Items)
                    {
                        if (item.Quantity <= item.Book.QuantityInStock)
                        {
                            var orderDetail = new OrderDetail
                            {
                                OrderId         = order.Id,
                                Book            = GetBookById(item.Book.Id),
                                QuantityOrdered = item.Quantity,
                            };
                            context.OrderDetails.Add(orderDetail);
                            var bookBought = context.Books.Find(item.Book.Id);
                            bookBought.QuantityInStock -= item.Quantity;
                        }
                        else
                        {
                            transaction.Rollback();
                            return(false);
                        }
                    }
                    context.SaveChanges();
                    transaction.Commit();
                    return(true);
                }

                catch (Exception E)
                {
                }
            }
            return(true);
        }
        public ActionResult AddToCart(int itemId, string name, float salePrice)
        {
            List <List <ShoppingCartModel> > shoppingCarts = new List <List <ShoppingCartModel> >();
            var currentUser   = context.Users.Where(b => b.UserName == User.Identity.Name).First();
            var orderAccepted = context.OrderRequest.Where(a => a.User.Id == currentUser.Id).First();

            if (orderAccepted.ActiveOrder == true || orderAccepted.OrderAccepted == true || orderAccepted.OrderPurchased == true)
            {
                return(View("CannotAdd"));
            }
            else
            {
                var myCartId = context.ShoppingcartJoin.Where(a => a.User.Id == currentUser.Id).ToList();
                foreach (var item in myCartId)
                {
                    shoppingCarts.Add(context.ShopingCarts.Where(a => a.Id == item.Id).ToList());
                }
                foreach (var item in shoppingCarts)
                {
                    foreach (var thing in item)
                    {
                        if (thing.itemId == itemId)
                        {
                            thing.amount++;
                            context.SaveChanges();
                            return(DisplayShoppingCart());
                        }
                        else if (thing.itemId == 0)
                        {
                            thing.amount     = 1;
                            thing.name       = name;
                            thing.salePrices = salePrice;
                            thing.itemId     = itemId;
                            context.SaveChanges();
                            return(DisplayShoppingCart());
                        }
                    }
                }
            }
            ShoppingCartModel shoppingCart = new ShoppingCartModel();

            shoppingCart.itemId     = itemId;
            shoppingCart.name       = name;
            shoppingCart.salePrices = salePrice;
            shoppingCart.amount     = 1;
            context.ShopingCarts.Add(shoppingCart);
            context.SaveChanges();
            ShoppingCartJoinModel ShoppingCartJoin = new ShoppingCartJoinModel();

            ShoppingCartJoin.shoppingCart = shoppingCart;
            ShoppingCartJoin.User         = context.Users.Where(a => a.Email == currentUser.Email).First();
            context.ShoppingcartJoin.Add(ShoppingCartJoin);
            context.SaveChanges();

            return(DisplayShoppingCart());
        }
Exemplo n.º 7
0
        // GET: ShoppingCart
        public ActionResult Index()
        {
            var data  = _shoppingCartService.GetBasket(userEmail).ToList().Select(p => PrepareShoppingCartModel(p));
            var model = new ShoppingCartModel {
                ShoppingModels    = _shoppingCartService.GetBasket(userEmail).ToList().Select(p => PrepareShoppingCartModel(p)),
                TopViewedProducts = _productService.GetTopViewedProducts().ToList().Select(p => PrepareProductModel(p, false))
            };

            return(View(model));
        }
Exemplo n.º 8
0
        public ActionResult MyCarts()
        {
            var currentId = Convert.ToInt32(AbpSession.UserId);
            var carts     = _cartService.GetAllShoppingItems(currentId);

            var model = new ShoppingCartModel();

            PrepareShoppingCartModel(model, carts.Items.ToList());
            return(View(model));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Display home screen for client.
        /// </summary>
        /// <returns>Home view.</returns>
        public IActionResult Home()
        {
            ShoppingCartModel        shoppingCart = GetCurrentBasket();
            IList <ProductViewModel> products     = httpHelper.TryGetCollectionFromApi <ProductViewModel>("api/products/getall");
            HomeViewModel            model        = new HomeViewModel {
                Catalog = products, ShoppingCart = shoppingCart
            };

            return(View(model));
        }
        public IViewComponentResult Invoke()
        {
            var cartId            = _cartIdProvider.CartId;
            var shoppingCartModel = new ShoppingCartModel(cartId)
            {
                ShoppingCartItems = _getShoppingCartItemsListQuery.Execute(cartId)
            };

            return(View(shoppingCartModel));
        }
Exemplo n.º 11
0
        public void Do(ShoppingCartModel cart)
        {
            var existingProduct = cart.Products.FirstOrDefault(p => p.Id == _product.Id);

            if (existingProduct != null)
            {
                _lastCount            = existingProduct.Count;
                existingProduct.Count = _count;
            }
        }
        public ActionResult MyProfile(ShoppingCartModel model)
        {
            List <ProfileDataModel> prof = model.getCustomerDetails((string)Session["USERID"]);

            if (!prof.Any())
            {
                ViewBag.Message = "Please Login to see your Profile";
            }
            return(View(prof));
        }
Exemplo n.º 13
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var shoppingCartItems = _getShoppingCartItemsListQuery.Execute(_cartIdProvider.CartId);

            var shoppingCartModel = new ShoppingCartModel(_cartIdProvider.CartId)
            {
                ShoppingCartItems = shoppingCartItems
            };

            return(View(shoppingCartModel));
        }
Exemplo n.º 14
0
        public ActionResult Cart()
        {
            var cart = _workContext.CurrentUser.ShoppingCartItems
                       .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
                       .ToList();

            var model = new ShoppingCartModel();

            PrepareShoppingCartModel(model, cart);
            return(View(model));
        }
Exemplo n.º 15
0
        public async Task Save(ShoppingCartModel shoppingCart)
        {
            using (var connection = new SqlConnection(_connectionString))
                using (var transaction = connection.BeginTransaction("Saving items into Cart"))
                {
                    await connection.ExecuteAsync(_clearCartSql, new { shoppingCart.UserId }, transaction)
                    .ConfigureAwait(false);

                    await connection.ExecuteAsync(_fillInCartSql, shoppingCart.Items, transaction);
                }
        }
Exemplo n.º 16
0
        public static ShoppingCart ConvertToShoppingCart(ShoppingCartModel shoppingCartModel)
        {
            ShoppingCart shoppingCart = new ShoppingCart
            {
                Id          = shoppingCartModel.Id,
                Amount      = shoppingCartModel.Amount,
                StoreItemId = shoppingCartModel.Id,
            };

            return(shoppingCart);
        }
Exemplo n.º 17
0
        private ShoppingCartModel GetCart()
        {
            ShoppingCartModel cart = (ShoppingCartModel)Session["Cart"];

            if (cart == null)
            {
                cart            = new ShoppingCartModel();
                Session["Cart"] = cart;
            }
            return(cart);
        }
Exemplo n.º 18
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            ShoppingCartModel cart = (ShoppingCartModel)controllerContext.HttpContext.Session[this.sessionKey];

            if (cart == null)
            {
                cart = new ShoppingCartModel();
                controllerContext.HttpContext.Session[this.sessionKey] = cart;
            }

            return(cart);
        }
        public ActionResult Login(ShoppingCartModel cartModel)
        {
            string UserID = cartModel.checkUser(cartModel.Email_Id, cartModel.password);

            if (!(UserID == null))
            {
                Session["USERNAME"] = cartModel.Email_Id;
                Session["USERID"]   = UserID;
                return(View("Success", cartModel));
            }
            return(View());
        }
 public JsonResult Products(ShoppingCartModel model)
 {
     try
     {
         List <ProductsModel> products = model.getProducts();
         return(Json(new { Result = "OK", Records = products }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { Result = "OK", Message = ex.Message }));
     }
 }
Exemplo n.º 21
0
        public async Task <IActionResult> PostShoppingCartModel([FromBody] ShoppingCartModel shoppingCartModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ShoppingCarts.Add(shoppingCartModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetShoppingCartModel", new { id = shoppingCartModel.ShoppingCartId }, shoppingCartModel));
        }
Exemplo n.º 22
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <AppDbContext>(options =>
                                          options.UseSqlServer(_configurationRoot.GetConnectionString("DefaultConnection"))); //add dbcontext for EF
     services.AddTransient <ICategoryRepository, CategoryRepository>();                                                       // register for DI
     services.AddTransient <IPieRepository, PieRepository>();
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddScoped <ShoppingCartModel>(sp => ShoppingCartModel.GetCart(sp));
     services.AddMvc();
     services.AddMemoryCache();
     services.AddSession();
 }
Exemplo n.º 23
0
 public IHttpActionResult Post([FromBody] ShoppingCartModel shoppingCartModel)
 {
     try
     {
         var cart = _service.CreateShoppingCart(shoppingCartModel);
         return(Ok(cart));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
        // GET: Carrito
        public ActionResult AgregarCarrito(int productID)
        {
            if (Session["shoppingCart"] == null)
            {
                List <ShoppingCartModel> shoppingCart = new List <ShoppingCartModel>();

                var productEntity = dbCtx.Products.Find(productID);

                ShoppingCartModel item = new ShoppingCartModel(productEntity)
                {
                    BarCode     = productEntity.BarCode,
                    Description = productEntity.ProductName,
                    Price       = productEntity.ProductPrice,
                    Quantity    = 1,
                    Total       = productEntity.ProductPrice * 1
                };

                shoppingCart.Add(item);

                Session["shoppingCart"] = shoppingCart;
            }
            else
            {
                List <ShoppingCartModel> shoppingCart = (List <ShoppingCartModel>)Session["shoppingCart"];

                int IndexExistente = getIndex(productID);

                if (IndexExistente == -1)
                {
                    var productEntity = dbCtx.Products.Find(productID);

                    ShoppingCartModel item = new ShoppingCartModel(productEntity)
                    {
                        BarCode     = productEntity.BarCode,
                        Description = productEntity.ProductName,
                        Price       = productEntity.ProductPrice,
                        Quantity    = 1,
                        Total       = productEntity.ProductPrice * 1
                    };

                    shoppingCart.Add(item);
                }
                else
                {
                    shoppingCart[IndexExistente].Quantity++;
                }

                Session["shoppingCart"] = shoppingCart;
            }


            return(View());
        }
Exemplo n.º 25
0
        public async Task <ActionResult> Print(long?id)
        {
            var stores = storeManager.SelectStores();

            var shoppingCart = shoppingCartManager.Select(id.Value);

            ShoppingCartModel model = ShoppingCartModel.FromBusinessEntity(shoppingCart);

            model.Stores = StoreModel.FromBusinessEntityCollection(stores);

            return(PartialView(model));
        }
        public virtual Response <IList <ShippingMethodModel> > GetShippingMethods(ShoppingCartModel shoppingCartModel, string storeName = "", AddressModel addressModel = null)
        {
            var customer = this.customerService.GetCustomerByGuid(shoppingCartModel.CustomerGuid);

            if (customer == null)
            {
                return(new Response <IList <ShippingMethodModel> >
                {
                    Success = false,
                    Message = "Cannot find customer by guid"
                });
            }

            if (customer.ShoppingCartItems == null)
            {
                return(new Response <IList <ShippingMethodModel> >
                {
                    Success = false,
                    Message = "Shopping curt items is null"
                });
            }

            var store = this.storeService.GetAllStores()
                        .FirstOrDefault(s => s.Name.Equals(storeName, StringComparison.CurrentCultureIgnoreCase));

            var address = addressModel != null
        ? addressModel.MapToAddress()
        : customer.ShippingAddress;

            var optionResponse = this.shippingService.GetShippingOptions(customer.ShoppingCartItems.ToList(), address, string.Empty, store == null ? 0 : store.Id);

            var result = new List <ShippingMethodModel>(0);

            if (optionResponse.Success)
            {
                foreach (var shippingOption in optionResponse.ShippingOptions)
                {
                    result.Add(new ShippingMethodModel
                    {
                        Name        = shippingOption.Name,
                        Description = shippingOption.Description,
                        SystemName  = shippingOption.ShippingRateComputationMethodSystemName
                    });
                }
            }

            return(new Response <IList <ShippingMethodModel> >
            {
                Success = true,
                Result = result
            });
        }
Exemplo n.º 27
0
 public ActionResult ShippingInfo(ShippingInfo ShippingInfo)
 {
     if (ModelState.IsValid)
     {
         ShoppingCartModel cart = GetCart();
         cart.ShippingInfo = ShippingInfo;
         return(RedirectToAction("BillingInfo"));
     }
     else
     {
         return(View(ShippingInfo));
     }
 }
Exemplo n.º 28
0
        public void UpdateShoppingCart(ShoppingCartModel shoppingCart)
        {
            ShoppingCart dbShoppingCart = dbContext.ShoppingCarts.FirstOrDefault(x => x.IdShoppingCart == shoppingCart.IdShoppingCart);

            if (dbShoppingCart != null)
            {
                dbShoppingCart.IdShoppingCart = shoppingCart.IdShoppingCart;
                dbShoppingCart.IdProduct      = shoppingCart.IdProduct;
                dbShoppingCart.Price          = shoppingCart.Price;
                dbShoppingCart.Quantity       = shoppingCart.Quantity;
                dbContext.SubmitChanges();
            }
        }
Exemplo n.º 29
0
        public virtual async Task <IActionResult> Cart(bool checkoutAttributes)
        {
            if (!await _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart))
            {
                return(RedirectToRoute("HomePage"));
            }

            var cart  = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
            var model = new ShoppingCartModel();
            await _shoppingCartViewModelService.PrepareShoppingCart(model, cart, validateCheckoutAttributes : checkoutAttributes);

            return(View(model));
        }
        public ActionResult AddToCart(int id, int quantity)
        {
            var product = dal.GetProduct(id);

            ShoppingCartModel cart = GetActiveShoppingCart();


            cart.AddToCart(product, quantity);

            Session["Shopping_Cart"] = cart;

            return(RedirectToAction("ViewCart", cart));
        }