public ActionResult Create(Budgets_Baskets budgets_permissions, int budgetId = 0) { if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { budgets_permissions.CompanyId = CurrentUser.CompanyId; bool wasCreated; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { wasCreated = permissionsRep.Create(budgets_permissions); } if (wasCreated) return RedirectToAction("Index", new { id = budgetId }); else return Error(Loc.Dic.error_permissions_create_error); } else { return Error(Loc.Dic.error_invalid_form); } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult Details(int id = 0) { if (Authorized(RoleType.SystemManager)) { Budgets_Baskets permission; using (BudgetsPermissionsRepository permissionRep = new BudgetsPermissionsRepository()) { permission = permissionRep.GetEntity(id); } if (permission != null) { if (permission.CompanyId == CurrentUser.CompanyId) { return(View(permission)); } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_permissions_get_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Edit(Budgets_Baskets budgets_permissions) { if (Authorized(RoleType.SystemManager)) { Budgets_Baskets permissionFromDB; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { permissionFromDB = permissionsRep.GetEntity(budgets_permissions.Id); if (permissionFromDB != null) { if (permissionFromDB.CompanyId == CurrentUser.CompanyId) { permissionFromDB.Name = budgets_permissions.Name; permissionsRep.Update(permissionFromDB); return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_permissions_get_error)); } } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Create(Budgets_Baskets budgets_permissions, int budgetId = 0) { if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { budgets_permissions.CompanyId = CurrentUser.CompanyId; bool wasCreated; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { wasCreated = permissionsRep.Create(budgets_permissions); } if (wasCreated) { return(RedirectToAction("Index", new { id = budgetId })); } else { return(Error(Loc.Dic.error_permissions_create_error)); } } else { return(Error(Loc.Dic.error_invalid_form)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult EditAllocations(int id = 0, int budgetId = 0) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } PermissionAllocationsModel model = new PermissionAllocationsModel(); Budget budget; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository()) { model.Basket = permissionsRep.GetEntity(id); if (model.Basket == null) { return(Error(Loc.Dic.error_permissions_get_error)); } if (model.Basket.CompanyId != CurrentUser.CompanyId) { return(Error(Loc.Dic.error_no_permission)); } budget = budgetsRep.GetEntity(budgetId); if (budget == null) { return(Error(Loc.Dic.error_database_error)); } List <PermissionAllocation> permissionsToAllocations = permissionsAllocationsRep.GetList("Budgets_Allocations", "Budgets_Allocations.Budgets_Incomes", "Budgets_Allocations.Budgets_Expenses") .Where(x => x.BudgetId == budget.Id && x.BasketId == model.Basket.Id) .AsEnumerable() .Select(alloc => new PermissionAllocation() { IsActive = true, Allocation = alloc }) .ToList(); model.BudgetAllocations = new BudgetAllocations() { Budget = budget, AllocationsList = budget.Budgets_Allocations.OrderBy(x => x.SortingCode).ToList(), PermissionAllocations = permissionsToAllocations }; return(View(model)); } }
public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } IEnumerable <Budgets_Baskets> permissions; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { permissions = permissionsRep.GetList("Budgets_BasketsToAllocation").Where(x => x.CompanyId == CurrentUser.CompanyId); permissions = Pagination(permissions, page, sortby, order, true); return(View(permissions.ToList())); } }
public ActionResult Create(int permissionId, int budgetId) { Budgets_BasketsToAllocation perAlloc = new Budgets_BasketsToAllocation(); using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRepository = new BudgetsPermissionsRepository()) using (AllocationRepository allocationRepository = new AllocationRepository(CurrentUser.CompanyId)) { ViewBag.AllocationList = new SelectList(allocationRepository.GetList().Where(x => x.BudgetId == budgetId).OrderBy(x => x.ExternalId).ToList(), "Id", "DisplayName"); //ViewBag.BudgetsAllocationId = new SelectList(db.Budgets_Allocations, "Id", "Id"); perAlloc.BudgetId = budgetId; perAlloc.BasketId = permissionId; Budget budget = budgetsRepository.GetEntity(budgetId); ViewBag.budgetYear = budget.Year; Budgets_Baskets permission = permissionsRepository.GetEntity(permissionId); ViewBag.PermissionName = permission.Name; } return(View(perAlloc)); }
public ActionResult Create(int permissionId, int budgetId) { Budgets_BasketsToAllocation perAlloc = new Budgets_BasketsToAllocation(); using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRepository = new BudgetsPermissionsRepository()) using (AllocationRepository allocationRepository = new AllocationRepository(CurrentUser.CompanyId)) { ViewBag.AllocationList = new SelectList(allocationRepository.GetList().Where(x => x.BudgetId == budgetId).OrderBy(x => x.ExternalId).ToList(), "Id", "DisplayName"); //ViewBag.BudgetsAllocationId = new SelectList(db.Budgets_Allocations, "Id", "Id"); perAlloc.BudgetId = budgetId; perAlloc.BasketId = permissionId; Budget budget = budgetsRepository.GetEntity(budgetId); ViewBag.budgetYear = budget.Year; Budgets_Baskets permission = permissionsRepository.GetEntity(permissionId); ViewBag.PermissionName = permission.Name; } return View(perAlloc); }
public ActionResult BudgetBaskets(int id = 0, int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); IEnumerable<Budgets_Baskets> baskets; Budgets_BasketsToAllocation per = new Budgets_BasketsToAllocation(); using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { baskets = permissionsRep.GetList("Budgets_BasketsToAllocation").Where(x => x.CompanyId == CurrentUser.CompanyId); baskets = Pagination(baskets, page, sortby, order, true); ViewBag.budgetId = id; Budget budget = budgetsRep.GetList().SingleOrDefault(x => x.Id == id); ViewBag.budgetYear = budget.Year; ViewBag.budgetId = budget.Id; return View(baskets.ToList()); } }
public ActionResult BudgetBaskets(int id = 0, int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } IEnumerable <Budgets_Baskets> baskets; Budgets_BasketsToAllocation per = new Budgets_BasketsToAllocation(); using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { baskets = permissionsRep.GetList("Budgets_BasketsToAllocation").Where(x => x.CompanyId == CurrentUser.CompanyId); baskets = Pagination(baskets, page, sortby, order, true); ViewBag.budgetId = id; Budget budget = budgetsRep.GetList().SingleOrDefault(x => x.Id == id); ViewBag.budgetYear = budget.Year; ViewBag.budgetId = budget.Id; return(View(baskets.ToList())); } }
public ActionResult EditBaskets(int id = 0) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } UserPermissionsModel model = new UserPermissionsModel(); User user; List <Budgets_Baskets> allPermissions; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { user = usersRep.GetEntity(id); if (user == null) { return(Error(Loc.Dic.error_users_get_error)); } model.User = user; model.UserPermissions = user.Budgets_UsersToBaskets.Select(x => new UserPermission() { Permission = x.Budgets_Baskets, IsActive = true }).Where(x => x.Permission.CompanyId == CurrentUser.CompanyId).ToList(); if (model.UserPermissions == null) { return(Error(Loc.Dic.error_permissions_get_error)); } allPermissions = permissionsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).ToList(); if (allPermissions == null) { return(Error(Loc.Dic.error_database_error)); } List <Budgets_Baskets> allWithoutUserBasket = new List <Budgets_Baskets>(); foreach (Budgets_Baskets basket in allPermissions) { allWithoutUserBasket.Add(basket); } foreach (UserPermission UserBasket in model.UserPermissions) { foreach (Budgets_Baskets basket in allPermissions) { if (UserBasket.Permission.Id == basket.Id) { allWithoutUserBasket.Remove(basket); } } } model.UserId = user.Id; model.PermissionsSelectList = new SelectList(allWithoutUserBasket, "Id", "Name"); return(View(model)); } }
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 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 Edit(int id = 0) { if (Authorized(RoleType.SystemManager)) { Budgets_Baskets permission; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { permission = permissionsRep.GetEntity(id); } if (permission != null) { if (permission.CompanyId == CurrentUser.CompanyId) { return View(permission); } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_permissions_get_error); } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult Edit(Budgets_Baskets budgets_permissions) { if (Authorized(RoleType.SystemManager)) { Budgets_Baskets permissionFromDB; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { permissionFromDB = permissionsRep.GetEntity(budgets_permissions.Id); if (permissionFromDB != null) { if (permissionFromDB.CompanyId == CurrentUser.CompanyId) { permissionFromDB.Name = budgets_permissions.Name; permissionsRep.Update(permissionFromDB); return RedirectToAction("Index"); } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_permissions_get_error); } } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult EditAllocations(int id = 0, int budgetId = 0) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); PermissionAllocationsModel model = new PermissionAllocationsModel(); Budget budget; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository()) { model.Basket = permissionsRep.GetEntity(id); if (model.Basket == null) return Error(Loc.Dic.error_permissions_get_error); if (model.Basket.CompanyId != CurrentUser.CompanyId) return Error(Loc.Dic.error_no_permission); budget = budgetsRep.GetEntity(budgetId); if (budget == null) return Error(Loc.Dic.error_database_error); List<PermissionAllocation> permissionsToAllocations = permissionsAllocationsRep.GetList("Budgets_Allocations", "Budgets_Allocations.Budgets_Incomes", "Budgets_Allocations.Budgets_Expenses") .Where(x => x.BudgetId == budget.Id && x.BasketId == model.Basket.Id) .AsEnumerable() .Select(alloc => new PermissionAllocation() { IsActive = true, Allocation = alloc }) .ToList(); model.BudgetAllocations = new BudgetAllocations() { Budget = budget, AllocationsList = budget.Budgets_Allocations.OrderBy(x=>x.SortingCode).ToList(), PermissionAllocations = permissionsToAllocations }; return View(model); } }
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 EditBaskets(int id = 0) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); UserPermissionsModel model = new UserPermissionsModel(); User user; List<Budgets_Baskets> allPermissions; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { user = usersRep.GetEntity(id); if (user == null) return Error(Loc.Dic.error_users_get_error); model.User = user; model.UserPermissions = user.Budgets_UsersToBaskets.Select(x => new UserPermission() { Permission = x.Budgets_Baskets, IsActive = true }).Where(x => x.Permission.CompanyId == CurrentUser.CompanyId).ToList(); if (model.UserPermissions == null) return Error(Loc.Dic.error_permissions_get_error); allPermissions = permissionsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).ToList(); if (allPermissions == null) return Error(Loc.Dic.error_database_error); List<Budgets_Baskets> allWithoutUserBasket = new List<Budgets_Baskets>(); foreach (Budgets_Baskets basket in allPermissions) allWithoutUserBasket.Add(basket); foreach (UserPermission UserBasket in model.UserPermissions) foreach (Budgets_Baskets basket in allPermissions) if (UserBasket.Permission.Id == basket.Id) allWithoutUserBasket.Remove(basket); model.UserId = user.Id; model.PermissionsSelectList = new SelectList(allWithoutUserBasket, "Id", "Name"); return View(model); } }
public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); IEnumerable<Budgets_Baskets> permissions; using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository()) { permissions = permissionsRep.GetList("Budgets_BasketsToAllocation").Where(x => x.CompanyId == CurrentUser.CompanyId); permissions = Pagination(permissions, page, sortby, order, true); return View(permissions.ToList()); } }
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 }); } }