Exemplo n.º 1
0
        // GET: ShipAddress
        public async Task <IActionResult> Index()
        {
            string             userID      = HttpContext.User.Identity.Name;
            List <ShipAddress> AddressList = await _addressRepository.GetAddressAsync(userID, _MaxAddressCount, 0);

            return(View(AddressList));
        }
        public async Task <IActionResult> Post([FromBody] AddShoppingCartModel model)
        {
            if (string.IsNullOrEmpty(model.UserID) ||
                Guid.Empty == model.ProductID || 0 >= model.Amount)
            {
                return(ResponseHelper.NotAcceptable());
            }
            var product = await _productRepository.GetAsync(model.ProductID);

            if (null == product)
            {
                return(NotFound());
            }

            List <ShipAddress> addressList = await _shipAddressRepository.GetAddressAsync(model.UserID, 50, 0);

            Order order = new Order()
            {
                Address     = addressList.Count > 0 ? addressList[0].ToString() + "(mobile)" : string.Empty + "(mobile)",
                OrderID     = Guid.NewGuid(),
                OrderDate   = DateTime.Now,
                OrderStatus = OrderStatus.PendingPayment,
                UserID      = model.UserID,
            };

            OrderDetail orderDetail = new OrderDetail()
            {
                OrderID        = order.OrderID,
                PlaceDate      = DateTime.Now,
                ProductName    = product.ProductName,
                ProductID      = product.ProductID,
                ThumbImagePath = product.ThumbnailImage,
                UnitPrice      = product.UnitPrice,
                Quantity       = model.Amount,
                SubTotal       = product.UnitPrice * model.Amount
            };

            order.TotalPrice = orderDetail.SubTotal;

            Guid orderID = await _orderRepository.AddAsync(order);

            // Add order failed.
            if (orderID == Guid.Empty)
            {
                return(ResponseHelper.InternalServerError());
            }

            int count = await _orderDetailRepository.AddAsync(orderDetail);

            if (0 < count)
            {
                return(Ok());
            }
            else
            {
                return(ResponseHelper.InternalServerError());
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Get()
        {
            string             userID      = HttpContext.User.Identity.Name;
            List <ShipAddress> addressList = await _shipAddressRepository.GetAddressAsync(userID, 0, 50);

            JsonResult result = new JsonResult(addressList);

            return(result);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Confirm([FromQuery] string idList, [FromQuery] string ProductID, [FromQuery] int Amount)
        {
            if (string.IsNullOrEmpty(idList) && string.IsNullOrEmpty(ProductID))
            {
                return(Redirect("/Home"));
            }

            string            userID            = HttpContext.User.Identity.Name;
            OrderConfirmModel orderConfirmModel = new OrderConfirmModel();

            orderConfirmModel.ShipAddresses = new List <SelectListItem>();
            orderConfirmModel.OrderItem     = new Order()
            {
                OrderID    = Guid.NewGuid(),
                UserID     = userID,
                OrderDate  = DateTime.Now,
                OrderState = OrderStatus.PendingPayment
            };


            Guid tempGuid = Guid.Empty;
            List <ShipAddress> addressStringList = await _shipAddressRepository.GetAddressAsync(userID, _MaxAddressCount, 0);

            foreach (ShipAddress sa in addressStringList)
            {
                orderConfirmModel.ShipAddresses.Add(
                    new SelectListItem {
                    Text = sa.ToString(), Value = sa.ToString()
                });
            }
            if (string.IsNullOrEmpty(idList))
            {
                orderConfirmModel.OrderDetails = await CreateOrderDetailsByProductAsync(
                    orderConfirmModel.OrderItem.OrderID, ProductID, Amount);
            }
            else
            {
                orderConfirmModel.OrderDetails = await CreateOrderDetailsByCartIDListAsync(
                    orderConfirmModel.OrderItem.OrderID, idList);
            }
            orderConfirmModel.IDList        = idList;
            orderConfirmModel.ProductID     = ProductID;
            orderConfirmModel.ProductAmount = Amount;
            foreach (OrderDetail od in orderConfirmModel.OrderDetails)
            {
                orderConfirmModel.TotalAmount += od.SubTotal;
            }

            return(View(orderConfirmModel));
        }