示例#1
0
        public IActionResult Delete(int Id)
        {
            UnitOfWork uow = new UnitOfWork();

            OrdersRepository        repo   = new OrdersRepository(uow);
            OrderProductsRepository opRepo = new OrderProductsRepository(uow);

            uow.BeginTransaction();
            try {
                Order order             = repo.GetById(Id, true);
                List <OrderProduct> ops = opRepo.GetAll(op => order.Id == op.OrderId);

                foreach (OrderProduct op in ops)
                {
                    opRepo.Delete(op);
                }
                repo.Delete(order);
                uow.Commit();
            }
            catch (Exception) {
                uow.Rollback();
            }
            finally{
                uow.Dispose();
            }

            return(RedirectToAction("Index", "Orders"));
        }
示例#2
0
        public IActionResult Details(int Id)
        {
            OrdersRepository        repo   = new OrdersRepository();
            OrderProductsRepository opRepo = new OrderProductsRepository();

            Order     order = repo.GetById(Id, true);
            DetailsVM model = new DetailsVM();

            model.Order = order;

            model.OrderProducts = opRepo.GetAll(op => op.OrderId == order.Id, 1, 10, true);

            return(View(model));
        }
示例#3
0
        public IActionResult Create(CreateVM model)
        {
            UnitOfWork              uow          = new UnitOfWork();
            OrdersRepository        ordersRepo   = new OrdersRepository(uow);
            OrderProductsRepository opRepo       = new OrderProductsRepository(uow);
            UsersRepository         usersRepo    = new UsersRepository(uow);
            ProductsRepository      productsRepo = new ProductsRepository(uow);

            User loggedUsed = usersRepo.GetFirstOrDefault(u => u.Username == HttpContext.Session.GetString("LoggedUsername"));

            uow.BeginTransaction();
            Order order = new Order(DateTime.Now, loggedUsed.Id);

            try {
                ordersRepo.Insert(order);

                for (int i = 0; i < model.Ids.Length; i++)
                {
                    if (model.Quantities[i] > 0)
                    {
                        OrderProduct op = new OrderProduct();
                        Product      p  = productsRepo.GetFirstOrDefault(pr => pr.Id == model.Ids[i]);

                        op.Order     = order;
                        op.ProductId = p.Id;
                        op.PriceSold = p.CurrentPrice;
                        op.Quantity  = model.Quantities[i];

                        opRepo.Insert(op);
                    }
                }
                uow.Commit();
            }
            catch (Exception) {
                uow.Rollback();
            }
            finally {
                uow.Dispose();
            }

            return(RedirectToAction("My", "Orders"));
        }
示例#4
0
        public ActionResult ProcessOrder()
        {
            OrderProductsRepository orderProductRepository = new OrderProductsRepository();
            Cart shoppingcart = new Cart();

            shoppingcart = (Cart)Session["cart"];
            var userId   = User.Identity.GetUserId();
            var customer = customerRepository.GetCustomerByUserId(userId);

            var order = new OrderModel()
            {
                CreatedDateTime = DateTime.Now,
                StartDate       = shoppingcart.StartDate,
                EndDate         = shoppingcart.EndDate,
                StatusID        = 1,
                Total           = shoppingcart.Total,
                ShopID          = (int)Session["shopId"],
                CustomerID      = customer.CustomerID
            };

            var orderId = orderRepository.InsertOrder(order);

            foreach (var productAdded in shoppingcart.productsList)
            {
                OrderProductModel orderproduct = new OrderProductModel();

                orderproduct.ProductID     = productAdded.ProductAddedID;
                orderproduct.OrderQuantity = productAdded.Count;
                orderproduct.OrderID       = orderId;
                orderproduct.OrderSatus    = "New";

                orderProductRepository.InsertOrderProduct(orderproduct);
            }

            Session["cart"]          = null;
            Session["numberofitems"] = null;


            return(View("OrderSucces"));
        }