Exemple #1
0
        public ActionResult AddressList()
        {
            var customer = workContext.GetAuthenticatedCustomer();

            if (customer == null)
            {
                return(RedirectToAction("SingIn", "Login"));
            }

            AddressListModel model = new AddressListModel();
            var cam = db.CustomerAddressMappings.Where(x => x.CustomerId == customer.Id).ToList();

            foreach (var addressId in cam)
            {
                var          address      = db.Addresses.FirstOrDefault(x => x.Id == addressId.AddressId);
                AddressModel addressModel = new AddressModel();
                addressModel.Id           = address.Id;
                addressModel.FirsName     = address.FirsName;
                addressModel.LastName     = address.LastName;
                addressModel.ProvinceId   = address.ProvinceId;
                addressModel.CountiesId   = address.CountiesId;
                addressModel.Address      = address.Address1;
                addressModel.Email        = address.Email;
                addressModel.Phone        = address.Phone;
                addressModel.CreatedOnUtc = address.CreatedOnUtc;
                model.Address.Add(addressModel);
            }

            return(View(model));
        }
Exemple #2
0
        // GET: Admin/Home
        public ActionResult Index()
        {
            var customer = workContext.GetAuthenticatedCustomer();

            if (customer == null)
            {
                return(RedirectToAction("SingIn", "../Login"));
            }
            return(View());
        }
Exemple #3
0
        public ActionResult CartList()
        {
            var customer = workContext.GetAuthenticatedCustomer();

            if (customer == null)
            {
                return(RedirectToAction("SingIn", "Login"));
            }

            var     cartList            = db.ShoppingCartItems.Where(x => x.CustomerId == customer.Id).ToList();
            decimal?totalprice          = 0;
            ShoppingCartListModel model = new ShoppingCartListModel();


            foreach (var item in cartList)
            {
                var product = db.Products.FirstOrDefault(x => x.Id == item.ProductId);

                var ShoppingCart = new ShoppingCartModel();
                ShoppingCart.Id          = item.Id;
                ShoppingCart.Quantity    = item.Quantity;
                ShoppingCart.ProductName = product.Name;
                ShoppingCart.ProductId   = product.Id;
                ShoppingCart.Price       = product.Price;
                ShoppingCart.Photo       = product.Photo;
                ShoppingCart.CustomerId  = item.CustomerId;
                totalprice += product.Price * item.Quantity;

                model.ShoppingCarts.Add(ShoppingCart);
            }
            model.TotalPrice    = totalprice;
            model.TotalQuantity = cartList.Count;

            return(PartialView("_ShoppingCart", model));
        }
Exemple #4
0
        public ActionResult Create(AddressCheckModel model)
        {
            var customer = workContext.GetAuthenticatedCustomer();

            if (customer == null)
            {
                return(RedirectToAction("SingIn", "Login"));
            }


            #region ShoppingCart
            var cartList = db.ShoppingCartItems.Where(x => x.CustomerId == customer.Id).ToList();

            decimal?totalprice = 0;
            foreach (var item in cartList)
            {
                var product = db.Products.FirstOrDefault(x => x.Id == item.ProductId);

                var ShoppingCart = new ShoppingCartModel();
                ShoppingCart.Id         = item.Id;
                ShoppingCart.Quantity   = item.Quantity;
                ShoppingCart.ProductId  = product.Id;
                ShoppingCart.Price      = product.Price;
                ShoppingCart.CustomerId = item.CustomerId;
                totalprice += product.Price * item.Quantity;

                model.ShoppingCarts.Add(ShoppingCart);
            }
            #endregion

            #region OrderCerate
            Order order = new Order();
            order.CustomerId       = customer.Id;
            order.AddressId        = model.AddressId;
            order.ShippingMethod   = model.Cargo;
            order.OrderStatusId    = (int)OrderStatusEnum.Preparing;
            order.ShippingStatusId = (int)ShippingStatusEnum.NotYetShipped;
            order.OrderTotal       = totalprice;
            order.Deleted          = false;
            order.CreatedOnUtc     = DateTime.Now;
            db.Orders.Add(order);
            if (db.SaveChanges() > 0)
            {
                foreach (var product in model.ShoppingCarts)
                {
                    OrderItem oi = new OrderItem();
                    oi.OrderId   = order.Id;
                    oi.ProductId = product.ProductId;
                    oi.Quantity  = product.Quantity;
                    oi.Price     = product.Price;
                    db.OrderItems.Add(oi);
                    if (db.SaveChanges() > 0)
                    {
                        var cart = db.ShoppingCartItems.SingleOrDefault(x => x.Id == product.Id && x.CustomerId == customer.Id);

                        if (cart != null)
                        {
                            db.ShoppingCartItems.Remove(cart);
                            db.SaveChanges();
                        }
                    }
                }
            }
            #endregion

            return(RedirectToAction("Index", "Home"));
        }