Ejemplo n.º 1
0
        public IActionResult SummaryPOST([FromBody] OrderHeaderViewModel form)
        {
            var orderHeader = new OrderHeader
            {
                Name         = form.Name,
                Status       = ConstantVariable.StatusSubmitted,
                Address      = form.Address,
                City         = form.City,
                Email        = form.Email,
                OrderDate    = DateTime.Now,
                Phone        = form.Phone,
                ServiceCount = form.serviceItems.Count,
                ZipCode      = form.ZipCode
            };

            unitOfWork.OrderHeader.Add(orderHeader);
            unitOfWork.Save();
            foreach (var item in form.serviceItems)
            {
                var details = new OrderDetails
                {
                    OrderHeaderId = orderHeader.Id,
                    Price         = item.Price,
                    ServiceId     = item.Id,
                    ServiceName   = item.Name
                };
                unitOfWork.OrderDetails.Add(details);
            }
            unitOfWork.Save();
            return(Ok("Ordered Successfully"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <OrderHeaderViewModel> > GetOrder(int id)
        {
            var getOrder = await _orderService.ReadOrderById(id);

            if (getOrder == null)
            {
                return(NotFound());
            }
            IList <OrderDetailViewModel> getDetails = new List <OrderDetailViewModel>();

            foreach (var el in getOrder.OrderDetails)
            {
                getDetails.Add(new OrderDetailViewModel
                {
                    Qty       = el.Qty,
                    ProductId = el.ProductId,
                    OrderId   = el.OrderId
                });
            }
            var orderVM = new OrderHeaderViewModel
            {
                OrderId       = getOrder.OrderId,
                Phone         = getOrder.Phone,
                Cost          = getOrder.Cost,
                CustomerEmail = getOrder.CustomerEmail,
                CreatedAt     = getOrder.CreatedAt,
                FullAddress   = getOrder.FullAddress,
                OrderStatus   = getOrder.OrderStatus,
                orderDetail   = getDetails
            };

            return(orderVM);
        }
Ejemplo n.º 3
0
        //訂單
        public ActionResult OrderList()
        {
            MemberService        service = new MemberService();
            OrderHeaderViewModel model   = new OrderHeaderViewModel();

            model.orderList = service.GetOrderHeader(Int32.Parse(Request.Cookies["upid"].Value));
            return(PartialView(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> New(OrderHeaderViewModel model)
        {
            Product product = await _context.Products.FindAsync(model.ProductId);

            if (product != null && hasErrors(model) != false)
            {
                OrderHeader orderHeader = new OrderHeader(product.Price, model.PaymentMethod, model.ShippingMethod, model.Billing, model.Shipping);
                OrderDetail orderDetail = new OrderDetail(product);

                orderHeader.Details.Add(orderDetail);

                await _context.OrdersHeader.AddAsync(orderHeader);

                await _context.SaveChangesAsync();

                return(View("Success"));
            }
            return(View("Failed"));
        }
        public ActionResult ViewOrder(int orderNumber)
        {
            var user = UserManager.FindById(User.Identity.GetUserId());

            if (user == null)
            {
                return(View("Error"));
            }

            OrderHeaderViewModel model = new OrderHeaderViewModel();

            model = OrderHeaderViewModel.GetOrder(orderNumber, user.Id);

            if (model.Order.TotalOrderValue == 0)
            {
                return(RedirectToAction("ViewOrderHistory"));
            }

            return(View(model));
        }
Ejemplo n.º 6
0
 private bool hasErrors(OrderHeaderViewModel model)
 {
     return(StringsUtil.ValidateString(model.PaymentMethod) && StringsUtil.ValidateString(model.ShippingMethod) &&
            ValidateShipping(model.Shipping) && ValidateBilling(model.Billing));
 }