コード例 #1
0
        public PartialViewResult GetOrder(string sortOrder, int?page)
        {
            ViewBag.DateSortOrder     = sortOrder == "DateSortOrder" ? "DateSortOrder_Desc" : "DateSortOrder";
            ViewBag.CustomerSortOrder = sortOrder == "CustomerSortOrder" ? "CustomerSortOrder_Desc" : "CustomerSortOrder";
            ViewBag.CurrentSort       = sortOrder;

            List <ManagementOrderViewModel> data = new List <ManagementOrderViewModel>();

            //Get order
            var orders = OrderRepos.GetAll();

            foreach (var order in orders)
            {
                var total = OrderDetailRepos.TotalOrder(order.ID);
                data.Add(new ManagementOrderViewModel
                {
                    Status    = order.Status,
                    Country   = order.Customer.Country.Name,
                    Customer  = order.Customer.Name,
                    OrderDate = order.OrderDate,
                    Id        = order.ID,
                    Total     = total
                });
            }
            var dashboards = SortOrder(sortOrder, data);
            int pageNumber = page ?? 1;

            return(PartialView(dashboards.ToPagedList(pageNumber, 25)));
        }
コード例 #2
0
ファイル: OrderController.cs プロジェクト: thientt/NALOrder
        public ActionResult Index(OrderViewModel order)
        {
            ViewBag.Error = "Error";

            if (ModelState.IsValid)
            {
                try
                {
                    var saveCustomer = CustomerRepos.AddCustomer(new CustomerDto()
                    {
                        Address   = order.Address,
                        CountryId = order.CountryId,
                        Email     = order.Email,
                        Name      = order.Name,
                        Phone     = order.Phone
                    });

                    var saveOrder = OrderRepos.AddOrder(new OrderDto
                    {
                        CustomerId = saveCustomer.ID,
                        OrderDate  = DateTime.Now,
                        Status     = StatusType.NEW,
                    });

                    //Remove first order
                    if (order.OrderDetail.Count > 0)
                    {
                        order.OrderDetail.RemoveAt(0);
                    }

                    if (order.OrderDetail.Count > 0)
                    {
                        foreach (var item in order.OrderDetail)
                        {
                            decimal price = ProductRepos.GetPrice(item.ProductId);

                            var saveOrderDetail = OrderDetailRepos.Add(new OrderDetailDto
                            {
                                OrderId   = saveOrder.ID,
                                ProductId = 1,
                                Quantity  = 1,
                                UnitPrice = price,
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogService.Error(ex.Message, ex);
                    return(View());
                }

                //Return page successfully
                return(RedirectToAction("ResultOrder", new { status = true }));// View(order);
            }

            return(View());
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private OrderViewModel GetInforOrder(int id)
        {
            //get customer
            OrderDto order = OrderRepos.Single(id);

            OrderViewModel data = new OrderViewModel();

            //Information customer
            data.Id           = id;
            data.Name         = order.Customer.Name;
            data.Address      = order.Customer.Address;
            data.Email        = order.Customer.Email;
            data.Phone        = order.Customer.Phone;
            data.CounntryName = order.Customer.Country.Name;
            data.DateOrder    = order.OrderDate;
            data.Status       = order.Status;

            //Information order detail
            List <OrderDetailDto> orderDetail = OrderDetailRepos.GetByOrder(id).ToList();

            if (data.OrderDetail == null)
            {
                data.OrderDetail = new List <OrderDetailViewModel>();
            }
            for (int i = 0; i < orderDetail.Count(); i++)
            {
                var item = orderDetail[i];
                data.OrderDetail.Add(new OrderDetailViewModel
                {
                    No          = i + 1,
                    Quality     = item.Quantity,
                    UnitPrice   = item.UnitPrice,
                    ProductName = item.Product.ProductName,
                    Total       = item.Total,
                });
            }

            return(data);
        }