public ActionResult DeleteConfirmed(int id, int budgetId) { if (Authorized(RoleType.SystemManager)) { Budgets_Baskets permission; using (OrdersRepository orderssRep = new OrdersRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository()) using (UsersToBasketsRepository usersPermissionsRep = new UsersToBasketsRepository()) { permission = permissionsRep.GetEntity(id); if (permission != null) { if (permission.CompanyId == CurrentUser.CompanyId) { bool noErrors = true; List <int> permissionAllocations = permission.Budgets_BasketsToAllocation.Select(x => x.Id).ToList(); List <int> usersPermissions = permission.Budgets_UsersToBaskets.Select(x => x.Id).ToList(); foreach (var itemId in permissionAllocations) { if (!permissionsAllocationsRep.Delete(itemId)) { noErrors = false; } } foreach (var itemId in usersPermissions) { if (!usersPermissionsRep.Delete(itemId)) { noErrors = false; } } if (!permissionsRep.Delete(permission.Id)) { noErrors = false; } if (noErrors) { return(RedirectToAction("Index", new { id = budgetId })); } else { return(Error(Loc.Dic.error_permissions_delete_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_projects_get_error)); } } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult DeleteConfirmed(int id) { return(Error(Loc.Dic.error_no_permission)); if (Authorized(RoleType.SystemManager)) { Budgets_Allocations allocation; using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId)) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) using (BasketsToAllocationsRepository allocationsPermissionsRep = new BasketsToAllocationsRepository()) { allocation = allocationsRep.GetEntity(id, "Budgets_Incomes", "Budgets_Expenses"); if (allocation != null) { if (allocation.CompanyId == CurrentUser.CompanyId) { if (false) //if (allocation.Orders.All(x => x.StatusId < (int)StatusType.ApprovedPendingInvoice)) { bool noErrors = true; List <Order> allocationOrders = new List <Order>();//List<Order> allocationOrders = allocation.Orders.ToList(); foreach (var item in allocationOrders) { item.StatusId = (int)StatusType.Declined; item.LastStatusChangeDate = DateTime.Now; //item.OrderApproverNotes = YOUR_ALLOCATION_WAS_REVOKED; item.NextOrderApproverId = null; if (ordersRep.Update(item) == null) { noErrors = false; } } List <int> allocationPermission = allocation.Budgets_BasketsToAllocation.Select(x => x.Id).ToList(); foreach (var itemId in allocationPermission) { if (!allocationsPermissionsRep.Delete(itemId)) { noErrors = false; } } if (!allocationsRep.Delete(allocation.Id)) { noErrors = false; } if (noErrors) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_allocations_delete_error)); } } else { return(Error(Loc.Dic.error_allocations_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)); } }
public ActionResult EditAllocations(PermissionAllocationsModel model) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } Budgets_Baskets permissionFromDB; List <Budgets_Allocations> existingPermissionAllocations; List <Budgets_BasketsToAllocation> existingPermissionToAllocations; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository()) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { permissionFromDB = permissionsRep.GetEntity(model.Basket.Id); //TODO: Error gets ALL pemissions from DB existingPermissionAllocations = permissionsAllocationsRep.GetList().Where(x => x.BasketId == permissionFromDB.Id).Select(y => y.Budgets_Allocations).ToList(); existingPermissionToAllocations = permissionsAllocationsRep.GetList().Where(x => x.BasketId == permissionFromDB.Id).ToList(); if (permissionFromDB == null) { return(Error(Loc.Dic.error_database_error)); } if (permissionFromDB.CompanyId != CurrentUser.CompanyId) { return(Error(Loc.Dic.error_no_permission)); } Budget budgetFromDB = budgetsRep.GetEntity(model.BudgetAllocations.Budget.Id); if (budgetFromDB == null) { return(Error(Loc.Dic.error_database_error)); } if (budgetFromDB.CompanyId != CurrentUser.CompanyId) { return(Error(Loc.Dic.error_no_permission)); } foreach (var allocation in model.BudgetAllocations.PermissionAllocations) { if (allocation.IsActive) { if (!existingPermissionAllocations.Any(x => x.Id == allocation.Allocation.BudgetsAllocationId)) { allocation.Allocation.BudgetId = budgetFromDB.Id; allocation.Allocation.BasketId = permissionFromDB.Id; if (!permissionsAllocationsRep.Create(allocation.Allocation)) { return(Error(Loc.Dic.error_database_error)); } } } else { if (existingPermissionAllocations.Any(x => x.Id == allocation.Allocation.BudgetsAllocationId)) { permissionsAllocationsRep.Delete(allocation.Allocation.Id); } } } return(RedirectToAction("BudgetBaskets", new { id = budgetFromDB.Id })); } }
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)); } }
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); } }
public ActionResult EditAllocations(PermissionAllocationsModel model) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); Budgets_Baskets permissionFromDB; List<Budgets_Allocations> existingPermissionAllocations; List<Budgets_BasketsToAllocation> existingPermissionToAllocations; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository()) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { permissionFromDB = permissionsRep.GetEntity(model.Basket.Id); //TODO: Error gets ALL pemissions from DB existingPermissionAllocations = permissionsAllocationsRep.GetList().Where(x => x.BasketId == permissionFromDB.Id).Select(y => y.Budgets_Allocations).ToList(); existingPermissionToAllocations = permissionsAllocationsRep.GetList().Where(x => x.BasketId == permissionFromDB.Id).ToList(); if (permissionFromDB == null) return Error(Loc.Dic.error_database_error); if (permissionFromDB.CompanyId != CurrentUser.CompanyId) return Error(Loc.Dic.error_no_permission); Budget budgetFromDB = budgetsRep.GetEntity(model.BudgetAllocations.Budget.Id); if (budgetFromDB == null) return Error(Loc.Dic.error_database_error); if (budgetFromDB.CompanyId != CurrentUser.CompanyId) return Error(Loc.Dic.error_no_permission); foreach (var allocation in model.BudgetAllocations.PermissionAllocations) { if (allocation.IsActive) { if (!existingPermissionAllocations.Any(x => x.Id == allocation.Allocation.BudgetsAllocationId)) { allocation.Allocation.BudgetId = budgetFromDB.Id; allocation.Allocation.BasketId = permissionFromDB.Id; if(!permissionsAllocationsRep.Create(allocation.Allocation)) return Error(Loc.Dic.error_database_error); } } else { if (existingPermissionAllocations.Any(x => x.Id == allocation.Allocation.BudgetsAllocationId)) { permissionsAllocationsRep.Delete(allocation.Allocation.Id); } } } return RedirectToAction("BudgetBaskets", new { id = budgetFromDB.Id }); } }
public ActionResult DeleteConfirmed(int id, int budgetId) { if (Authorized(RoleType.SystemManager)) { Budgets_Baskets permission; using (OrdersRepository orderssRep = new OrdersRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository()) using (UsersToBasketsRepository usersPermissionsRep = new UsersToBasketsRepository()) { permission = permissionsRep.GetEntity(id); if (permission != null) { if (permission.CompanyId == CurrentUser.CompanyId) { bool noErrors = true; List<int> permissionAllocations = permission.Budgets_BasketsToAllocation.Select(x => x.Id).ToList(); List<int> usersPermissions = permission.Budgets_UsersToBaskets.Select(x => x.Id).ToList(); foreach (var itemId in permissionAllocations) { if (!permissionsAllocationsRep.Delete(itemId)) noErrors = false; } foreach (var itemId in usersPermissions) { if (!usersPermissionsRep.Delete(itemId)) noErrors = false; } if (!permissionsRep.Delete(permission.Id)) noErrors = false; if (noErrors) return RedirectToAction("Index", new { id = budgetId }); else return Error(Loc.Dic.error_permissions_delete_error); } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_projects_get_error); } } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult DeleteConfirmed(int id) { return Error(Loc.Dic.error_no_permission); if (Authorized(RoleType.SystemManager)) { Budgets_Allocations allocation; using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId)) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) using (BasketsToAllocationsRepository allocationsPermissionsRep = new BasketsToAllocationsRepository()) { allocation = allocationsRep.GetEntity(id, "Budgets_Incomes", "Budgets_Expenses"); if (allocation != null) { if (allocation.CompanyId == CurrentUser.CompanyId) { if (false) //if (allocation.Orders.All(x => x.StatusId < (int)StatusType.ApprovedPendingInvoice)) { bool noErrors = true; List<Order> allocationOrders = new List<Order>();//List<Order> allocationOrders = allocation.Orders.ToList(); foreach (var item in allocationOrders) { item.StatusId = (int)StatusType.Declined; item.LastStatusChangeDate = DateTime.Now; //item.OrderApproverNotes = YOUR_ALLOCATION_WAS_REVOKED; item.NextOrderApproverId = null; if (ordersRep.Update(item) == null) noErrors = false; } List<int> allocationPermission = allocation.Budgets_BasketsToAllocation.Select(x => x.Id).ToList(); foreach (var itemId in allocationPermission) { if (!allocationsPermissionsRep.Delete(itemId)) noErrors = false; } if (!allocationsRep.Delete(allocation.Id)) noErrors = false; if (noErrors) return RedirectToAction("Index"); else return Error(Loc.Dic.error_allocations_delete_error); } else { return Error(Loc.Dic.error_allocations_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); } }