Esempio n. 1
0
        /// <summary>
        /// 获取订单消息数据列表
        /// </summary>
        /// <param name="userId">当前登录用户</param>
        /// <param name="pageindex">页码</param>
        /// <returns>系统消息ViewModel</returns>
        public OrderInformationViewModel GetOrderMsg(int userId, int pageindex)
        {
            OrderInformationViewModel viewmodel = new OrderInformationViewModel();

            try
            {
                int totalRecord = 0, pageCount = 0;
                var list = InformationBll.GetOrderInfoList(userId, pageindex, PageSize);
                totalRecord = list.FirstOrDefault().TotalRecord;
                pageCount   = totalRecord / PageSize;
                if (totalRecord % PageSize > 0)
                {
                    pageCount += 1;
                }
                viewmodel.MessageList = list;
                viewmodel.PageSize    = PageSize;
                viewmodel.PageCount   = pageCount;
                viewmodel.TotalRecord = totalRecord;
                viewmodel.PageIndex   = pageindex;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
            }
            return(viewmodel);
        }
Esempio n. 2
0
 public async Task <Order> ProcessOrderAsync(BasketViewModel basket, OrderInformationViewModel orderInformation)
 {
     return(await orderRepository.AddOrderAsync((order) =>
     {
         orderOperations.AddUserInformationToOrder(ref order, orderInformation);
         orderOperations.AddOrderInformationToOrder(ref order, basket, orderInformation);
         orderOperations.AddBasketLinesToOrder(basket, ref order);
     }));
 }
Esempio n. 3
0
        public void FillUserPersonalInformationProperties(OrderInformationViewModel model, ref User user)
        {
            UserPersonalInformation userPersonalInformation = new UserPersonalInformation()
            {
                Name        = model.Name,
                Surname     = model.Surname,
                PhoneNumber = model.PhoneNumber,
            };

            user.UserPersonalInformation = userPersonalInformation;
        }
Esempio n. 4
0
        public void FillUserAddressProperties(OrderInformationViewModel model, ref User user)
        {
            UserAddress userAddress = new UserAddress()
            {
                Country  = model.Country,
                City     = model.City,
                Address  = model.Address,
                Address2 = model.Address2,
                ZipCode  = model.ZipCode,
            };

            user.UserAddress = userAddress;
        }
Esempio n. 5
0
        public void AddUserInformationToOrder(ref Order order, OrderInformationViewModel orderInformation)
        {
            var user = userRepository.GetUserByEmail(orderInformation.Email);

            if (user == null)
            {
                user = new User
                {
                    Email = orderInformation.Email
                };

                FillUserAddressProperties(orderInformation, ref user);
                FillUserPersonalInformationProperties(orderInformation, ref user);

                order.User = user;
            }
            else
            {
                order.UserId = user.UserId;
            }
        }
Esempio n. 6
0
        public async Task PlaceOrder(ICollection <ProductInCartViewModel> products, OrderInformationViewModel userInformation)
        {
            var order = new Order
            {
                FirstName            = userInformation.FirstName,
                LastName             = userInformation.LastName,
                Address              = userInformation.Address,
                City                 = userInformation.City,
                Country              = userInformation.Country,
                Email                = userInformation.Email,
                PhoneNumber          = userInformation.PhoneNumber,
                ZipCode              = (int)userInformation.ZipCode,
                AditionalInfromation = userInformation.SanitizedInformation,
                CreatedOn            = DateTime.UtcNow,
                OrderStatus          = OrderStatus.Pending,
            };

            foreach (var product in products)
            {
                var targetProduct = await this.db.Products.FirstOrDefaultAsync(x => x.Id == product.Id);

                order.OrderProducts.Add(new OrderProduct
                {
                    ProductId      = product.Id,
                    OrderId        = order.Id,
                    WantedQuantity = product.WantedQuantity,
                });

                targetProduct.AvailableQuantity =
                    Math.Max(0, product.AvailableQuantity - product.WantedQuantity);
                this.db.Products.Update(targetProduct);
                await this.db.SaveChangesAsync();
            }

            this.db.Orders.Add(order);
            await this.db.SaveChangesAsync();
        }
        public async Task <ActionResult> OrderOverview(OrderInformationViewModel orderInformation)
        {
            Order order;
            var   basket = checkoutApi.GetCurrentBasket();

            if (basket.Lines.Count() == 0)
            {
                TempData["message"] = string.Format("Your basket is empty");
                return(RedirectToAction("Index", "Basket"));
            }

            if (ModelState.IsValid)
            {
                order = await checkoutApi.ProcessOrderAsync(basket, orderInformation);

                ViewBag.OrderId = order.OrderId;
            }
            else
            {
                return(View("OrderInformation"));
            }

            return(View(basket));
        }
Esempio n. 8
0
        public void AddOrderInformationToOrder(ref Order order, BasketViewModel basket, OrderInformationViewModel orderInformationViewModel)
        {
            order.Status = OrderStatuses.Pending;

            OrderInformation orderInformation = new OrderInformation()
            {
                Date     = DateTime.Today,
                Total    = basket.BasketTotal,
                Delivery = orderInformationViewModel.Delivery,
                Payment  = orderInformationViewModel.Payment,
            };

            order.OrderInformation = orderInformation;
        }