Ejemplo n.º 1
0
        public IActionResult Store()
        {
            List <int> shoppingCart = HttpContext.Session.Get <List <int> >("ShoppingCart");

            ShoppingCartViewModel.Order.CreatedAt = DateTime.Now;

            Order order = ShoppingCartViewModel.Order;

            _orderRepository.Create(order);

            int orderID = order.OrderID;

            foreach (int productID in shoppingCart)
            {
                OrderDetail orderDetail = new OrderDetail()
                {
                    OrderID   = orderID,
                    ProductID = productID
                };

                _orderDetailRepository.Create(orderDetail);
            }

            _orderDetailRepository.Save();
            shoppingCart = new List <int>();
            HttpContext.Session.Set("ShoppingCart", shoppingCart);

            return(RedirectToAction("Summary", "Order", new { area = "Store", id = orderID }));
        }
Ejemplo n.º 2
0
        public IActionResult EditDetails(EditOrderDetailModel orderDetailModel)
        {
            if (orderDetailModel.OrderDetailToppings != null)
            {
                orderDetailModel.OrderDetailToppings.RemoveAll(t => !t.IsChecked);
            }
            var isNew = orderDetailModel.OrderDetailId == 0;

            var orderDetail = isNew ? new OrderDetail() : _orderDetailRepository.GetById(orderDetailModel.OrderDetailId);

            _mapper.Map(orderDetailModel, orderDetail);

            //set drink name/drink size if new
            if (isNew)
            {
                var drink = _drinkRepository.GetDrinkById(orderDetail.DrinkId);
                orderDetail.DrinkName  = drink.Name;
                orderDetail.IsNewDrink = drink.IsNew;
            }

            var drinkSize = _drinkRepository.GetSizeById(orderDetailModel.DrinkSizeId);

            orderDetail.DrinkSize = drinkSize.Name;
            orderDetail.Price     = drinkSize.Price;

            //update price
            orderDetail.FullPrice = orderDetail.Price + (orderDetail.OrderDetailToppings?.Sum(t => t.Price * t.Quantity) ?? 0);
            orderDetail.Amount    = orderDetail.FullPrice * orderDetail.Quantity;

            var success = isNew ? _orderDetailRepository.Create(orderDetail) : _orderDetailRepository.Edit(orderDetail);

            if (success)
            {
                TempData["Message"] = "Lưu thành công";
            }
            else
            {
                TempData["Message"] = "Lưu thất bại";
            }

            //update order
            var order = _orderRepository.GetById(orderDetail.OrderId);

            order.IsSpecialPromo = _promotionRepository.CheckPromotionBuy1Get1();
            _orderRepository.Edit(order);

            return(new RedirectResult(Url.Action("Edit", new { orderId = orderDetail.OrderId }) + "#editdrinks"));
        }
Ejemplo n.º 3
0
        public IActionResult Order(int id, int pid)
        {
            var userID    = Task.Run(async() => await userManager.FindByNameAsync(User.Identity.Name)).Result.Id;
            var rolecheck = (from role in context.UserRoles.ToList()
                             where role.UserId == userID
                             select role).FirstOrDefault();

            if (rolecheck != null)
            {
                if (id != 0)
                {
                    var table   = orderRepository.Get(id);
                    var product = productRepository.Get(pid);

                    var od = new OrderDetail();
                    od.OrderId = table.OrderId;
                    if (orderDetailRepository.Create(od) != null)
                    {
                        var creatOd = new OrderCreateViewModel();

                        creatOd.TableId       = id;
                        creatOd.Using         = table.Using;
                        creatOd.OrderDetailId = (from odr in orderDetailRepository.Gets()
                                                 select odr.OrderDetailId).Max();
                        if (productOrderDetailRepository.Gets().Count() != 0)
                        {
                            creatOd.ProductOrderDetailId = (from podr in productOrderDetailRepository.Gets()
                                                            select podr.ProductOrderDetailId).Max() + 1;
                        }
                        else
                        {
                            creatOd.ProductOrderDetailId = 1;
                        }

                        creatOd.Name      = product.Name;
                        creatOd.Count     = 1;
                        creatOd.ProductId = pid;

                        return(View(creatOd));
                    }
                }
                return(Redirect("https://localhost:44366/"));
            }
            return(RedirectToAction("AccessDenied", "Account"));
        }
Ejemplo n.º 4
0
        public IActionResult Order(CustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User();
                if (signInManager.IsSignedIn(User))
                {
                    user = userManager.FindByNameAsync(User.Identity.Name).Result;
                }
                var product =
                    (from p in context.Products where p.IsDeleted == false && p.ProductId == model.ProductId select p)
                    .ToList().FirstOrDefault();
                var customer = new Customer
                {
                    CustomerName = model.Name,
                    Address      = model.Address,
                    PhoneNumber  = model.PhoneNumber,
                    UserId       = signInManager.IsSignedIn(User) ? user.Id : null
                };
                var createCustomer = customerRepository.Create(customer);
                var order          = new Order
                {
                    CustomerId = createCustomer.CustomerId,
                    OrderTime  = DateTime.Now,
                    Status     = OrderStatus.Pending
                };
                var createOrder = orderRepository.Create(order);
                var orderDetail = new OrderDetail
                {
                    OrderId   = createOrder.OrderId,
                    ProductId = product.ProductId,
                    Price     = product.Price,
                    Quantity  = 1
                };
                var createOrderDetail = orderDetailRepository.Create(orderDetail);
                context.Products.Find(model.ProductId).Remain -= 1;
                context.SaveChanges();
                return(RedirectToAction("OrderDetail", new { id = createOrder.OrderId }));
            }

            return(View());
        }
Ejemplo n.º 5
0
 public async Task CreateOrderDetail(OrderDetail data)
 {
     await _orderDetailRepository.Create(data);
 }