public IActionResult Detail(int orderId)
        {
            List <BillViewModel> bill = new List <BillViewModel>();

            Order order = _orderService.GetOrderWithId(orderId);

            if (order is null)
            {
                return(NotFound());
            }


            Address OrderAddress = _addressService.GetAddressesByUserId(order.CustomerId)
                                   .Single(I => I.Id == order.AddressId);
            Shipper OrderShipper = _shipperService.GetAllShippers().Single(I => I.Id == order.ShipperId);

            OrderDetailViewModel model = new OrderDetailViewModel()
            {
                OrderId          = order.Id,
                OrderDate        = order.OrderDate,
                ShipDate         = order.ShipDate,
                ShipStatus       = order.IsShipped ? "Kargoya Verildi" : "Kargoya Verilmedi",
                AllowStatus      = order.IsAllowed ? "Onaylandı" : "Onay Bekliyor",
                PaymentMethod    = _paymentService.GetPaymentNameWithId(order.PaymentId),
                CustomerFullName = _appUserService.GetOrderOwnerFullNameWithUserId(order.CustomerId),

                AddressId           = order.AddressId,
                AddressLine         = OrderAddress.AddressLine,
                AddressCity         = OrderAddress.City,
                AddressDistrict     = OrderAddress.District,
                AddressNeighborhood = OrderAddress.Neighborhood,
                AddressPostalCode   = OrderAddress.PostalCode,

                ShipperCompanyName = OrderShipper.CompanyName,
                ShipperPhone       = OrderShipper.Phone
            };

            model.OrderDetails = _orderDetailService.GetAllOrderDetails().Where(I => I.OrderId == orderId).ToList();

            foreach (var orderDetail in model.OrderDetails)
            {
                bill.Add(new BillViewModel()
                {
                    UnitPrice  = orderDetail.Price,
                    OrderId    = orderDetail.OrderId,
                    Quantity   = orderDetail.Quantity,
                    Product    = _productService.Products.Single(I => I.Id == orderDetail.ProductId),
                    TotalPrice = _orderDetailService.ComputeTotalPriceOfOrder(model.OrderId),
                });
            }

            model.Bill = bill;

            return(View(model));
        }
Beispiel #2
0
        public List <OrderSummaryViewModel> GetAllOrderSummaries(AppUser appUser)
        {
            List <OrderSummaryViewModel> model = new List <OrderSummaryViewModel>();

            var orders = _orderService.GetAllOrders().Where(I => I.CustomerId == appUser.Id).ToList();

            foreach (var order in orders)
            {
                var           orderDetails  = _orderDetailService.GetAllOrderDetails().Where(I => I.OrderId == order.Id).ToList();
                List <int>    productIds    = orderDetails.Select(I => I.ProductId).ToList();
                List <string> productImages = new List <string>();

                foreach (var productId in productIds)
                {
                    productImages.Add(_productService.Products.Single(I => I.Id == productId).Image1);
                }

                string paymentMethod      = _paymentService.GetPaymentNameWithId(order.PaymentId);
                string orderOwnerFullName = _appUserService.GetOrderOwnerFullNameWithUserId(order.CustomerId);


                model.Add(new OrderSummaryViewModel()
                {
                    OrderId          = order.Id,
                    OrderDate        = order.OrderDate,
                    CustomerFullName = orderOwnerFullName,
                    ShipStatus       = order.IsShipped ? "Kargoya Verildi" : "Kargoya Verilmedi",
                    AllowStatus      = order.IsAllowed ? "Onaylandı" : "Onay Bekliyor",
                    ProductCount     = _orderDetailService.ComputeTotalProductCount(order.Id),
                    TotalPrice       = _orderDetailService.ComputeTotalPriceOfOrder(order.Id),
                    ProductImages    = productImages
                });
            }

            return(model);
        }