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")); }
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)); }