public async Task <ActionResult> Delete(int id)
        {
            var   repository = new OrdersRepository(_context);
            Order order      = await repository.GetById(id);

            if (order == null)
            {
                return(NotFound());
            }

            try
            {
                repository.Delete(order);
                repository.Save();

                return(NoContent());
            }
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    message = e.Message.Replace('{', '(').Replace('}', ')')
                }));
            }
        }
Beispiel #2
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"));
        }
Beispiel #3
0
        public ActionResult Delete(int id)
        {
            _orderRepo.Delete(id);

            TempData["Message"] = "The order was successfully deleted!";

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Delete(int id)
        {
            OrdersRepository ordersRepo = new OrdersRepository();
            Order            order      = ordersRepo.GetById(id);
            int loggedUserId            = ((User)Session["loggedUser"]).Id;

            ordersRepo.Delete(order);

            return(RedirectToAction(loggedUserId == 1 ? "AdminPanel" : "Index", "Account"));
        }
Beispiel #5
0
        public IHttpActionResult Delete(int id)
        {
            var order = ordersRepo.GetById(id);

            if (order == null || order.IsDeleted)
            {
                return(NotFound());
            }
            ordersRepo.Delete(id);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #6
0
        public string Delete(int id)
        {
            Order order = _repo.Get(id);

            if (order == null)
            {
                throw new Exception("Invalid Id");
            }
            _repo.Delete(id);
            return("Successfully deleted");
        }
Beispiel #7
0
        public async Task Delete(params object[] keys)
        {
            using (var context = new NorthwindDbContext(_options))
            {
                var order = await Get(keys);

                var repository = new OrdersRepository(context);
                repository.Delete(order);
                repository.Save();
            }
        }
Beispiel #8
0
        public string Delete(int id, string userId)
        {
            Order order = _repo.Get(id);

            if (order == null || order.UserId != userId)
            {
                throw new Exception("Invalid Request");
            }
            _repo.Delete(id);
            return("Successfully Booted");
        }
Beispiel #9
0
        public void TestSave()
        {
            // подготовка
            var order = NewTestOrder();

            try
            {
                // выполнение
                repository.Save(order);
                // проверка
                Order o_db = repository.GetAll().FirstOrDefault(o => o.Id == order.Id);
                Assert.IsTrue(o_db != null);
                EqualOrder(order, o_db);
            }
            finally
            {
                if (order.Id != 0)
                {
                    repository.Delete(order);
                }
            }
        }
        public void OrdersRepositoryTests_Delete()
        {
            OrdersRepository repository = new OrdersRepository();
            var model = new Orders
            {
                Order_ID = 5
            };

            repository.Delete(5);
            var result = repository.GetByOrder_ID(5);

            Assert.IsTrue(result == null);
        }
        public async Task <ActionResult> Delete([FromODataUri] int key)
        {
            var   repository = new OrdersRepository(_context);
            Order order      = await repository.GetById(key);

            if (order == null)
            {
                return(NotFound());
            }
            repository.Delete(order);
            repository.Save();
            return(StatusCode((int)HttpStatusCode.NoContent));
        }
 public async Task DeleteOrder(Guid id)
 {
     try
     {
         await _repository.Delete(id);
     }
     catch (Exception e)
     {
         throw new ApplicationException(e.Message);
     }
     finally
     {
         await _repository.Save();
     }
 }
        public async Task Delete(params object[] keys)
        {
            using (var context = new NorthwindDbContext(_options))
            {
                try
                {
                    var order = await Get(keys);

                    var repository = new OrdersRepository(context);
                    repository.Delete(order);
                    repository.Save();
                }
                catch (Exception)
                {
                    throw new GridException("Error deleting the order");
                }
            }
        }
Beispiel #14
0
        public ActionResult DeleteConfirmed(int id = 0)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            Order order;
            using (OrderToItemRepository orderToItemRep = new OrderToItemRepository())
            using (OrderToAllocationRepository orderToAllocationRep = new OrderToAllocationRepository())
            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = orderRep.GetEntity(id);

                if (order == null) return Error(Loc.Dic.error_order_not_found);
                if (order.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);
                if (order.StatusId != (int)StatusType.Pending && order.StatusId != (int)StatusType.PendingOrderCreator)
                    return Error(Loc.Dic.error_order_delete_after_approval);

                if (!orderRep.Delete(order.Id)) return Error(Loc.Dic.error_orders_delete_error);
            }

            return RedirectToAction("MyOrders");
        }
Beispiel #15
0
        public ActionResult Create(CreateOrderModel model)
        {
            /// Validating user input
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);
            if (!ModelState.IsValid) return Error(Loc.Dic.error_invalid_form);
            if (String.IsNullOrEmpty(model.ItemsString)) return Error(Loc.Dic.error_invalid_form);
            List<Orders_OrderToItem> ItemsList = ItemsFromString(model.ItemsString, 0);
            if (ItemsList == null || ItemsList.Count == 0) return Error(Loc.Dic.error_invalid_form);
            if (model.IsFutureOrder && !Authorized(RoleType.FutureOrderWriter)) return Error(Loc.Dic.Error_NoPermission);
            if (model.Allocations == null || model.Allocations.Where(x => x.IsActive).Count() == 0) return Error(Loc.Dic.error_invalid_form);
            model.Allocations = model.Allocations.Where(x => x.IsActive).ToList();
            decimal totalOrderPrice = (decimal.Floor(ItemsList.Sum(x => x.SingleItemPrice * x.Quantity) * 1000) / 1000);
            decimal totalAllocation = (decimal.Floor(model.Allocations.Sum(x => x.Amount) * 1000) / 1000);
            if (totalOrderPrice != totalAllocation) return Error(Loc.Dic.error_order_insufficient_allocation);

            // Initializing needed temporary variables
            bool allowExeeding = true;
            List<Orders_OrderToAllocation> AllocationsToCreate = new List<Orders_OrderToAllocation>();

            // Setting order properties
            model.Order.UserId = CurrentUser.UserId;
            model.Order.Price = totalOrderPrice;
            model.Order.IsFutureOrder = model.IsFutureOrder;

            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId))
            {
                Budget currentBudget = budgetsRep.GetList().SingleOrDefault(x => x.IsActive);
                if (currentBudget == null) return Error(Loc.Dic.error_database_error);
                model.Order.BudgetId = currentBudget.Id;

                int[] orderAllocationsIds = model.Allocations.Select(x => x.AllocationId).Distinct().ToArray();
                var allocationsData = allocationsRep.GetAllocationsData(orderAllocationsIds, StatusType.Pending);
                bool IsValidAllocations =
                    (allocationsData.Count == orderAllocationsIds.Length) &&
                    model.Allocations.All(x => (x.MonthId == null || (x.MonthId >= 1 && x.MonthId <= 12)) && x.Amount > 0);
                if (!IsValidAllocations) return Error(Loc.Dic.error_invalid_form);

                if (model.IsFutureOrder)
                {
                    foreach (var allocationData in allocationsData)
                    {
                        List<OrderAllocation> allocationMonths = model.Allocations.Where(x => x.AllocationId == allocationData.AllocationId).ToList();

                        foreach (var month in allocationMonths)
                        {
                            if (month.MonthId == DateTime.Now.Month)
                            {
                                OrderAllocation currentAllocation = model.Allocations.SingleOrDefault(x => x.AllocationId == allocationData.AllocationId);

                                var newAllocations = allocationsRep.GenerateOrderAllocations(allocationData, currentAllocation.Amount, allowExeeding, DateTime.Now.Month);
                                if (newAllocations == null) return Error(Loc.Dic.error_order_insufficient_allocation);

                                AllocationsToCreate.AddRange(newAllocations);
                            }
                            else
                            {
                                var monthData = allocationData.Months.SingleOrDefault(x => x.MonthId == month.MonthId);
                                if (!allowExeeding && month.Amount > monthData.RemainingAmount) return Error(Loc.Dic.error_order_insufficient_allocation);

                                Orders_OrderToAllocation newAllocation = new Orders_OrderToAllocation()
                                {
                                    AllocationId = allocationData.AllocationId,
                                    MonthId = month.MonthId.Value,
                                    Amount = month.Amount,
                                    OrderId = 0
                                };

                                AllocationsToCreate.Add(newAllocation);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var allocationData in allocationsData)
                    {
                        OrderAllocation currentAllocation = model.Allocations.SingleOrDefault(x => x.AllocationId == allocationData.AllocationId);

                        var newAllocations = allocationsRep.GenerateOrderAllocations(allocationData, currentAllocation.Amount, allowExeeding, DateTime.Now.Month);
                        if (newAllocations == null) return Error(Loc.Dic.error_order_insufficient_allocation);

                        AllocationsToCreate.AddRange(newAllocations);
                    }
                }

                if (!CurrentUser.OrdersApprovalRouteId.HasValue)
                {
                    model.Order.NextOrderApproverId = null;
                    model.Order.StatusId = (int)StatusType.ApprovedPendingInvoice;
                }
                else
                {
                    Users_ApprovalRoutes orderRoute = routesRep.GetEntity(CurrentUser.OrdersApprovalRouteId.Value, "Users_ApprovalStep");
                    Users_ApprovalStep firstStep = orderRoute.Users_ApprovalStep.OrderBy(x => x.StepNumber).FirstOrDefault();

                    if (firstStep != null)
                    {
                        model.Order.ApprovalRouteId = orderRoute.Id;
                        model.Order.ApprovalRouteStep = firstStep.StepNumber;
                        model.Order.NextOrderApproverId = firstStep.UserId;
                        model.Order.StatusId = (int)StatusType.Pending;
                    }
                    else
                    {
                        model.Order.ApprovalRouteStep = null;
                        model.Order.NextOrderApproverId = null;
                        model.Order.StatusId = (int)StatusType.ApprovedPendingInvoice;
                    }
                }
            }

            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            using (OrderToItemRepository orderToItemRep = new OrderToItemRepository())
            using (OrderToAllocationRepository orderAllocationsRep = new OrderToAllocationRepository())
            {
                bool creationError = false;
                if (!ordersRep.Create(model.Order)) return Error(Loc.Dic.error_orders_create_error);

                model.Order = ordersRep.GetEntity(model.Order.Id, "User", "User1");

                foreach (Orders_OrderToItem item in ItemsList)
                {
                    item.OrderId = model.Order.Id;

                    if (!orderToItemRep.Create(item))
                    {
                        creationError = true;
                        break;
                    }
                }

                foreach (var allocation in AllocationsToCreate)
                {
                    allocation.OrderId = model.Order.Id;

                    if (!orderAllocationsRep.Create(allocation))
                    {
                        creationError = true;
                        break;
                    }
                }

                if (creationError)
                {
                    ordersRep.Delete(model.Order.Id);
                    return Error(Loc.Dic.error_orders_create_error);
                }
            }

            using (OrdersHistoryRepository ordersHistoryRepository = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, model.Order.Id))
            {
                Orders_History orderHis = new Orders_History();
                ordersHistoryRepository.Create(orderHis, (int)HistoryActions.Created, model.NotesForApprover);
            }

            if (model.Order.NextOrderApproverId.HasValue)
            {
                SendNotifications.OrderPendingApproval(model.Order, Url);
            }

            return RedirectToAction("MyOrders");
        }
Beispiel #16
0
        public ActionResult DeleteConfirmed(int id)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                using (BasketsToAllocationsRepository permissionAllocationsRep = new BasketsToAllocationsRepository())
                {
                    expense = expensesRep.GetEntity(id, "Budget", "Budgets_Incomes_types", "Budgets_Incomes_Institutions");

                    if (expense != null)
                    {
                        if (expense.CompanyId == CurrentUser.CompanyId)
                        {
                            List<Budgets_Allocations> expenseAllocations;
                            List<Budgets_BasketsToAllocation> expensePermissions;
                            List<Order> expenseOrders = ordersRep.GetList().Where(x => x.CompanyId == expense.Id).ToList(); //List<Order> expenseOrders = ordersRep.GetList().Where(x => x.Budgets_Allocations.ExpenseId == expense.Id).ToList();

                            if (!expenseOrders.Any(o => o.StatusId >= (int)StatusType.ApprovedPendingInvoice))
                            {
                                try
                                {
                                    expenseAllocations = allocationsRep.GetList().Where(x => x.ExpenseId == expense.Id).ToList();
                                    expensePermissions = permissionAllocationsRep.GetList().Where(x => x.Budgets_Allocations.ExpenseId == expense.Id).ToList();

                                    foreach (var item in expenseOrders)
                                    {
                                        ordersRep.Delete(item.Id);
                                    }

                                    foreach (var item in expensePermissions)
                                    {
                                        permissionAllocationsRep.Delete(item.Id);
                                    }

                                    foreach (var item in expenseAllocations)
                                    {
                                        allocationsRep.Delete(item.Id);
                                    }

                                    expensesRep.Delete(expense.Id);
                                }
                                catch
                                {
                                    return Error(Loc.Dic.error_database_error);
                                }

                                return RedirectToAction("Index");
                            }
                            else
                            {
                                return Error(Loc.Dic.error_expenses_delete_has_approved_orders);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_expenses_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Beispiel #17
0
        public ActionResult DeleteConfirmed(int id)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Incomes income;
                using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                    using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                        using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                            using (BasketsToAllocationsRepository permissionAllocationsRep = new BasketsToAllocationsRepository())
                            {
                                income = incomesRep.GetEntity(id, "Budget", "Budgets_Incomes_types", "Budgets_Incomes_Institutions");

                                if (income != null)
                                {
                                    if (income.CompanyId == CurrentUser.CompanyId)
                                    {
                                        List <Budgets_Allocations>         incomeAllocations;
                                        List <Budgets_BasketsToAllocation> incomePermissions;
                                        List <Order> incomeOrders = ordersRep.GetList().Where(x => x.CompanyId == income.Id).ToList(); //List<Order> incomeOrders = ordersRep.GetList().Where(x => x.Budgets_Allocations.IncomeId == income.Id).ToList();

                                        if (!incomeOrders.Any(o => o.StatusId >= (int)StatusType.ApprovedPendingInvoice))
                                        {
                                            try
                                            {
                                                incomeAllocations = allocationsRep.GetList().Where(x => x.IncomeId == income.Id).ToList();
                                                incomePermissions = permissionAllocationsRep.GetList().Where(x => x.Budgets_Allocations.IncomeId == income.Id).ToList();

                                                foreach (var item in incomeOrders)
                                                {
                                                    ordersRep.Delete(item.Id);
                                                }

                                                foreach (var item in incomePermissions)
                                                {
                                                    permissionAllocationsRep.Delete(item.Id);
                                                }

                                                foreach (var item in incomeAllocations)
                                                {
                                                    allocationsRep.Delete(item.Id);
                                                }

                                                incomesRep.Delete(income.Id);
                                            }
                                            catch
                                            {
                                                return(Error(Loc.Dic.error_database_error));
                                            }

                                            return(RedirectToAction("Index"));
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_income_delete_has_approved_orders));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_no_permission));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_income_get_error));
                                }
                            }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }