Example #1
0
        public async Task <IViewComponentResult> InvokeAsync(PurchaseModel purchaseModel)
        {
            Guid             customerId = purchaseModel.CustomerId;
            BillingInfoModel model;

            var customer = await customerService.GetCustomer(customerId);

            var billing = await orderService.GetDefaultBilling(customerId);

            if (billing != null)
            {
                model = mapper.Map <BillingInfoModel>(billing);

                if (customer != null)
                {
                    model.CustomerId = customer.Id;
                    model.FirstName  = customer.FirstName;
                    model.LastName   = customer.LastName;
                }
            }
            else
            {
                model = mapper.Map <BillingInfoModel>(customer);
            }

            purchaseModel.Billing = model;
            return(View(purchaseModel));
        }
        private async Task <PurchaseModel> CreateOrder(PurchaseModel model, SiteUser user, ShoppingCartDTO cart)
        {
            var customer = await customerService.GetCustomer(user.CustomerId);

            var billing = mapper.Map <BillingAddressDTO>(model.Billing);

            var order = await orderService.CreateOrder(customer, cart, billing);

            //on error return false;
            model.Order = mapper.Map <OrderModel>(order);

            return(model);
        }
Example #3
0
        public async Task <IActionResult> Index()
        {
            var user = await GetSiteUser();

            var customer = await customerService.GetCustomer(user.CustomerId);

            var orders = await orderService.GetCustomerOrders(user.CustomerId);

            var orderModels = mapper.Map <IEnumerable <OrderModel> >(orders);

            orderModels = orderModels.OrderBy(x => x.OrderDate);

            var customerModel = mapper.Map <CustomerModel>(customer);

            var model = new CustomerOrdersModel {
                Customer = customerModel, Orders = orderModels
            };

            return(View(model));
        }