public ActionResult Details(int id = 0) { if (Authorized(RoleType.SystemManager)) { Budget budget; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) { budget = budgetsRep.GetEntity(id, "Company"); } if (budget != null) { if (budget.CompanyId == CurrentUser.CompanyId) { return(View(budget)); } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_budgets_get_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Create(int id = 0) { return(Error(Loc.Dic.error_no_permission)); if (Authorized(RoleType.SystemManager)) { Budget budget; List <SelectListItemDB> incomesList; List <SelectListItemDB> expensesList; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository()) using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) { budget = budgetsRep.GetEntity(id); if (budget != null) { if (budget.CompanyId == CurrentUser.CompanyId) { incomesList = incomesRep.GetList() .Where(income => income.CompanyId == CurrentUser.CompanyId && income.BudgetId == budget.Id) .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.CustomName }) .ToList(); expensesList = expensesRep.GetList() .Where(expense => expense.CompanyId == CurrentUser.CompanyId && expense.BudgetId == budget.Id) .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.CustomName }) .ToList(); ViewBag.BudgetId = id; ViewBag.IncomeId = new SelectList(incomesList, "Id", "Name"); ViewBag.ExpenseId = new SelectList(expensesList, "Id", "Name"); return(View()); } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_database_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 Create(int id = 0) { return Error(Loc.Dic.error_no_permission); if (Authorized(RoleType.SystemManager)) { Budget budget; List<SelectListItemDB> incomesList; List<SelectListItemDB> expensesList; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository()) using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) { budget = budgetsRep.GetEntity(id); if (budget != null) { if (budget.CompanyId == CurrentUser.CompanyId) { incomesList = incomesRep.GetList() .Where(income => income.CompanyId == CurrentUser.CompanyId && income.BudgetId == budget.Id) .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.CustomName }) .ToList(); expensesList = expensesRep.GetList() .Where(expense => expense.CompanyId == CurrentUser.CompanyId && expense.BudgetId == budget.Id) .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.CustomName }) .ToList(); ViewBag.BudgetId = id; ViewBag.IncomeId = new SelectList(incomesList, "Id", "Name"); ViewBag.ExpenseId = new SelectList(expensesList, "Id", "Name"); return View(); } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_database_error); } } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult Export(int id = 0) { if (Authorized(RoleType.SystemManager)) { Budget budgetFromDb; List <Budgets_Allocations> allocations = new List <Budgets_Allocations>(); using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) { budgetFromDb = budgetsRep.GetEntity(id, "Budgets_Allocations.Budgets_AllocationToMonth"); if (budgetFromDb != null) { allocations = budgetFromDb.Budgets_Allocations.ToList(); } } if (allocations != null) { StringBuilder builder = new StringBuilder(); foreach (var allocation in allocations) { for (int monthNumber = 1; monthNumber <= 12; monthNumber++) { var allocationMonth = allocation.Budgets_AllocationToMonth.SingleOrDefault(x => x.MonthId == monthNumber); decimal monthAmount = allocationMonth == null ? 0 : allocationMonth.Amount; builder.Append(String.Format("{0} ", monthAmount)); } builder.AppendLine(); } return(File(Encoding.UTF8.GetBytes(builder.ToString()), "text/plain", string.Format("{0} - Budget {1}.txt", CurrentUser.CompanyName, budgetFromDb.Year))); } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Import(int?id) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } if (!id.HasValue) { return(View()); } using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) ViewBag.Year = budgetsRepository.GetEntity(id.Value).Year; return(View(id)); }
public ActionResult AllocationMontheList(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_Allocations> allocationsList; using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { allocationsList = allocationsRep.GetList("Budgets_AllocationToMonth").Where(x => x.BudgetId == id); allocationsList = Pagination(allocationsList, page, sortby, order); ViewBag.BudgetId = id; ViewBag.Year = budgetsRepository.GetEntity(id).Year; return View(allocationsList.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 ActivateConfirmed(int id) { if (Authorized(RoleType.SystemManager)) { Budget budget; using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) { budget = budgetRep.GetEntity(id); if (budget != null) { if (!budget.IsActive) { Budget oldBudget = budgetRep.GetList().Where(b => b.CompanyId == CurrentUser.CompanyId).SingleOrDefault(x => x.IsActive); if (oldBudget != null) { oldBudget.IsActive = false; budgetRep.Update(oldBudget); } budget.IsActive = true; budgetRep.Update(budget); return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_budgets_already_active)); } } else { return(Error(Loc.Dic.error_budgets_get_error)); } } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult ActivateConfirmed(int id) { if (Authorized(RoleType.SystemManager)) { Budget budget; using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) { budget = budgetRep.GetEntity(id); if (budget != null) { if (!budget.IsActive) { Budget oldBudget = budgetRep.GetList().Where(b => b.CompanyId == CurrentUser.CompanyId).SingleOrDefault(x => x.IsActive); if (oldBudget != null) { oldBudget.IsActive = false; budgetRep.Update(oldBudget); } budget.IsActive = true; budgetRep.Update(budget); return RedirectToAction("Index"); } else { return Error(Loc.Dic.error_budgets_already_active); } } else { return Error(Loc.Dic.error_budgets_get_error); } } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult AllocationMontheList(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_Allocations> allocationsList; using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { allocationsList = allocationsRep.GetList("Budgets_AllocationToMonth").Where(x => x.BudgetId == id); allocationsList = Pagination(allocationsList, page, sortby, order); ViewBag.BudgetId = id; ViewBag.Year = budgetsRepository.GetEntity(id).Year; return(View(allocationsList.ToList())); } }
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 Edit(Budgets_Expenses budgets_expenses) { return(Error(Loc.Dic.Error_NoPermission)); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budgets_Expenses expenseFromDB; Budget budget; Projects_ParentProject project; Projects_SubProject subProject; using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) using (ParentProjectsRepository projectsRep = new ParentProjectsRepository()) using (SubProjectsRepository subProjectsRep = new SubProjectsRepository()) { expenseFromDB = expensesRep.GetEntity(budgets_expenses.Id); budget = budgetRep.GetEntity(budgets_expenses.BudgetId); project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value); subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value); if (expenseFromDB != null) { if (budget != null && project != null && subProject != null) { if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId) { if (project.IsActive && subProject.IsActive) { if (budgets_expenses.Amount < expenseFromDB.Amount) { decimal?allocatedToExpense; using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { allocatedToExpense = allocationsRep.GetList() .Where(x => x.ExpenseId == expenseFromDB.Id) .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount); } if (allocatedToExpense.HasValue && allocatedToExpense > budgets_expenses.Amount) { return(Error(Loc.Dic.error_expenses_allocations_exeeds_amount)); } } expenseFromDB.BudgetId = budgets_expenses.BudgetId; expenseFromDB.ParentProjectId = budgets_expenses.ParentProjectId; expenseFromDB.SubProjectId = budgets_expenses.SubProjectId; expenseFromDB.Amount = budgets_expenses.Amount; expenseFromDB.CustomName = budgets_expenses.CustomName; Budgets_Expenses update = expensesRep.Update(expenseFromDB); if (update != null) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_expenses_create_error)); } } else { return(Error(Loc.Dic.error_invalid_form)); } } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(Loc.Dic.error_expenses_get_error)); } } } else { return(Error(ModelState)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Create(Budgets_Expenses budgets_expenses) { return(Error(Loc.Dic.Error_NoPermission)); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budget budget; Projects_ParentProject project; Projects_SubProject subProject; using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) using (ParentProjectsRepository projectsRep = new ParentProjectsRepository()) using (SubProjectsRepository subProjectsRep = new SubProjectsRepository()) { budget = budgetRep.GetEntity(budgets_expenses.BudgetId); project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value); subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value); } if (budget != null && project != null && subProject != null) { if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId) { if (project.IsActive && subProject.IsActive) { bool wasCreated; budgets_expenses.CompanyId = CurrentUser.CompanyId; using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) { wasCreated = expensesRep.Create(budgets_expenses); } if (wasCreated) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_expenses_create_error)); } } else { return(Error(Loc.Dic.error_invalid_form)); } } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(ModelState)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult DeleteConfirmed(int id) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); Budget budget; List<Budgets_Allocations> budgetAllocations; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { budget = budgetsRep.GetEntity(id); if (budget == null) return Error(Loc.Dic.error_database_error); if (budget.CompanyId != CurrentUser.CompanyId) return Error(Loc.Dic.error_no_permission); budgetAllocations = budget.Budgets_Allocations.ToList(); bool isTrueDelete = true; if (budgetAllocations.Any()) { foreach (var allocation in budgetAllocations) { if ( allocation.Budgets_BasketsToAllocation.Any() || allocation.Orders_OrderToAllocation.Any() ) { isTrueDelete = false; break; } } } bool wasDeleted; if (isTrueDelete) { wasDeleted = budgetsRep.Delete(id); } else { budget.IsCanceled = false; wasDeleted = budgetsRep.Update(budget) != null; } if (wasDeleted) return RedirectToAction("Index"); else return Error(Loc.Dic.error_budget_delete_error); } }
public ActionResult DeleteConfirmed(int id) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } Budget budget; List <Budgets_Allocations> budgetAllocations; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { budget = budgetsRep.GetEntity(id); if (budget == null) { return(Error(Loc.Dic.error_database_error)); } if (budget.CompanyId != CurrentUser.CompanyId) { return(Error(Loc.Dic.error_no_permission)); } budgetAllocations = budget.Budgets_Allocations.ToList(); bool isTrueDelete = true; if (budgetAllocations.Any()) { foreach (var allocation in budgetAllocations) { if ( allocation.Budgets_BasketsToAllocation.Any() || allocation.Orders_OrderToAllocation.Any() ) { isTrueDelete = false; break; } } } bool wasDeleted; if (isTrueDelete) { wasDeleted = budgetsRep.Delete(id); } else { budget.IsCanceled = false; wasDeleted = budgetsRep.Update(budget) != null; } if (wasDeleted) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_budget_delete_error)); } } }
public ActionResult Edit(Budgets_Incomes budgets_incomes) { return(Error(Loc.Dic.Error_NoPermission)); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budgets_Incomes incomeFromDB; Budget budget; Budgets_Incomes_types incomeType; Budgets_Incomes_Institutions institution; using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository()) using (IncomeTypesRepository incomeTypesRep = new IncomeTypesRepository()) using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) using (InstitutionsRepository InstitutionsRep = new InstitutionsRepository()) { incomeFromDB = incomesRep.GetEntity(budgets_incomes.Id); budget = budgetRep.GetEntity(budgets_incomes.BudgetId); incomeType = incomeTypesRep.GetEntity(budgets_incomes.BudgetIncomeTypeId); if (budgets_incomes.BudgetsIncomeInstitutionsId.HasValue) { institution = InstitutionsRep.GetEntity(budgets_incomes.BudgetsIncomeInstitutionsId.Value); } else { institution = null; } if (incomeFromDB != null) { if (budget != null && incomeType != null && (!budgets_incomes.BudgetsIncomeInstitutionsId.HasValue || institution != null)) { if (incomeFromDB.CompanyId == CurrentUser.CompanyId && budget.CompanyId == CurrentUser.CompanyId && (!budgets_incomes.BudgetsIncomeInstitutionsId.HasValue || institution.CompanyId == CurrentUser.CompanyId)) { if (budgets_incomes.Amount < incomeFromDB.Amount) { decimal?allocatedIncome; using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { allocatedIncome = allocationsRep.GetList() .Where(x => x.IncomeId == incomeFromDB.Id) .Sum(allocation => (decimal?)allocation.CompanyId);//.Sum(allocation => (decimal?)allocation.Amount); } if (allocatedIncome.HasValue && allocatedIncome > budgets_incomes.Amount) { return(Error(Loc.Dic.error_income_allocations_exeeds_amount)); } } incomeFromDB.BudgetId = budgets_incomes.BudgetId; incomeFromDB.BudgetIncomeTypeId = budgets_incomes.BudgetIncomeTypeId; incomeFromDB.BudgetsIncomeInstitutionsId = budgets_incomes.BudgetsIncomeInstitutionsId; incomeFromDB.CustomName = budgets_incomes.CustomName; incomeFromDB.Amount = budgets_incomes.Amount; Budgets_Incomes update = incomesRep.Update(incomeFromDB); if (update != null) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_income_create_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(Loc.Dic.error_income_get_error)); } } } else { return(Error(ModelState)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Details(int id = 0) { if (Authorized(RoleType.SystemManager)) { Budget budget; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) { budget = budgetsRep.GetEntity(id, "Company"); } if (budget != null) { if (budget.CompanyId == CurrentUser.CompanyId) { return View(budget); } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_budgets_get_error); } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult Create(Budgets_Incomes budgets_incomes) { return(Error(Loc.Dic.Error_NoPermission)); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budget budget; Budgets_Incomes_types incomeType; Budgets_Incomes_Institutions institution; using (IncomeTypesRepository incomeTypesRep = new IncomeTypesRepository()) using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) using (InstitutionsRepository InstitutionsRep = new InstitutionsRepository()) { budget = budgetRep.GetEntity(budgets_incomes.BudgetId); incomeType = incomeTypesRep.GetEntity(budgets_incomes.BudgetIncomeTypeId); if (budgets_incomes.BudgetsIncomeInstitutionsId.HasValue) { institution = InstitutionsRep.GetEntity(budgets_incomes.BudgetsIncomeInstitutionsId.Value); } else { institution = null; } } if (budget != null && incomeType != null && (!budgets_incomes.BudgetsIncomeInstitutionsId.HasValue || institution != null)) { if (budget.CompanyId == CurrentUser.CompanyId && (!budgets_incomes.BudgetsIncomeInstitutionsId.HasValue || institution.CompanyId == CurrentUser.CompanyId)) { bool wasCreated; budgets_incomes.CompanyId = CurrentUser.CompanyId; using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository()) { wasCreated = incomesRep.Create(budgets_incomes); } if (wasCreated) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_income_create_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(ModelState)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Create(Budgets_Expenses budgets_expenses) { return Error(Loc.Dic.Error_NoPermission); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budget budget; Projects_ParentProject project; Projects_SubProject subProject; using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) using (ParentProjectsRepository projectsRep = new ParentProjectsRepository()) using (SubProjectsRepository subProjectsRep = new SubProjectsRepository()) { budget = budgetRep.GetEntity(budgets_expenses.BudgetId); project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value); subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value); } if (budget != null && project != null && subProject != null) { if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId) { if (project.IsActive && subProject.IsActive) { bool wasCreated; budgets_expenses.CompanyId = CurrentUser.CompanyId; using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) { wasCreated = expensesRep.Create(budgets_expenses); } if (wasCreated) return RedirectToAction("Index"); else return Error(Loc.Dic.error_expenses_create_error); } else { return Error(Loc.Dic.error_invalid_form); } } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_database_error); } } else { return Error(ModelState); } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult Export(int id = 0) { if (Authorized(RoleType.SystemManager)) { Budget budgetFromDb; List<Budgets_Allocations> allocations = new List<Budgets_Allocations>(); using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) { budgetFromDb = budgetsRep.GetEntity(id, "Budgets_Allocations.Budgets_AllocationToMonth"); if (budgetFromDb != null) { allocations = budgetFromDb.Budgets_Allocations.ToList(); } } if (allocations != null) { StringBuilder builder = new StringBuilder(); foreach (var allocation in allocations) { for (int monthNumber = 1; monthNumber <= 12; monthNumber++) { var allocationMonth = allocation.Budgets_AllocationToMonth.SingleOrDefault(x => x.MonthId == monthNumber); decimal monthAmount = allocationMonth == null ? 0 : allocationMonth.Amount; builder.Append(String.Format("{0} ", monthAmount)); } builder.AppendLine(); } return File(Encoding.UTF8.GetBytes(builder.ToString()), "text/plain", string.Format("{0} - Budget {1}.txt", CurrentUser.CompanyName, budgetFromDb.Year)); } else { return Error(Loc.Dic.error_database_error); } } else { return Error(Loc.Dic.error_no_permission); } }
public ActionResult Import(int? id) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); if (!id.HasValue) return View(); using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) ViewBag.Year = budgetsRepository.GetEntity(id.Value).Year; return View(id); }
public ActionResult Create(Budgets_Allocations Budgets_Allocations, int id = 0) { return(Error(Loc.Dic.error_no_permission)); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budget budget; Budgets_Incomes income; Budgets_Expenses expense; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository()) using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { budget = budgetsRep.GetEntity(id); if (budget != null) { if (budget.CompanyId == CurrentUser.CompanyId) { income = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value); expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value); if (income != null && expense != null) { if (income.BudgetId == budget.Id && expense.BudgetId == budget.Id) { decimal?allocatedToExpense; decimal?allocatedToIncome; allocatedToIncome = allocationsRep.GetList() .Where(x => x.IncomeId == income.Id) .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount); if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount) //if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount) { return(Error(Loc.Dic.error_income_full_allocation)); } allocatedToExpense = allocationsRep.GetList() .Where(x => x.ExpenseId == expense.Id) .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount); if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount) //if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount) { return(Error(Loc.Dic.error_expenses_full_allocation)); } Budgets_Allocations.CompanyId = CurrentUser.CompanyId; Budgets_Allocations.BudgetId = budget.Id; Budgets_Allocations.CompanyId = CurrentUser.CompanyId; if (allocationsRep.Create(Budgets_Allocations)) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(Loc.Dic.error_invalid_form)); } } else { return(Error(Loc.Dic.error_database_error)); } } else { return(Error(Loc.Dic.error_no_permission)); } } else { return(Error(Loc.Dic.error_database_error)); } } } else { return(Error(ModelState)); } } 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(Budgets_Expenses budgets_expenses) { return Error(Loc.Dic.Error_NoPermission); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budgets_Expenses expenseFromDB; Budget budget; Projects_ParentProject project; Projects_SubProject subProject; using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) using (ParentProjectsRepository projectsRep = new ParentProjectsRepository()) using (SubProjectsRepository subProjectsRep = new SubProjectsRepository()) { expenseFromDB = expensesRep.GetEntity(budgets_expenses.Id); budget = budgetRep.GetEntity(budgets_expenses.BudgetId); project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value); subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value); if (expenseFromDB != null) { if (budget != null && project != null && subProject != null) { if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId) { if (project.IsActive && subProject.IsActive) { if (budgets_expenses.Amount < expenseFromDB.Amount) { decimal? allocatedToExpense; using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { allocatedToExpense = allocationsRep.GetList() .Where(x => x.ExpenseId == expenseFromDB.Id) .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount); } if (allocatedToExpense.HasValue && allocatedToExpense > budgets_expenses.Amount) return Error(Loc.Dic.error_expenses_allocations_exeeds_amount); } expenseFromDB.BudgetId = budgets_expenses.BudgetId; expenseFromDB.ParentProjectId = budgets_expenses.ParentProjectId; expenseFromDB.SubProjectId = budgets_expenses.SubProjectId; expenseFromDB.Amount = budgets_expenses.Amount; expenseFromDB.CustomName = budgets_expenses.CustomName; Budgets_Expenses update = expensesRep.Update(expenseFromDB); if (update != null) return RedirectToAction("Index"); else return Error(Loc.Dic.error_expenses_create_error); } else { return Error(Loc.Dic.error_invalid_form); } } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_database_error); } } else { return Error(Loc.Dic.error_expenses_get_error); } } } else { return Error(ModelState); } } 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 Create(Budgets_Allocations Budgets_Allocations, int id = 0) { return Error(Loc.Dic.error_no_permission); if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { Budget budget; Budgets_Incomes income; Budgets_Expenses expense; using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId)) using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository()) using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository()) using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId)) { budget = budgetsRep.GetEntity(id); if (budget != null) { if (budget.CompanyId == CurrentUser.CompanyId) { income = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value); expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value); if (income != null && expense != null) { if (income.BudgetId == budget.Id && expense.BudgetId == budget.Id) { decimal? allocatedToExpense; decimal? allocatedToIncome; allocatedToIncome = allocationsRep.GetList() .Where(x => x.IncomeId == income.Id) .Sum(allocation => (decimal?)allocation.CompanyId);//.Sum(allocation => (decimal?)allocation.Amount); if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount)//if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount) return Error(Loc.Dic.error_income_full_allocation); allocatedToExpense = allocationsRep.GetList() .Where(x => x.ExpenseId == expense.Id) .Sum(allocation => (decimal?)allocation.CompanyId);//.Sum(allocation => (decimal?)allocation.Amount); if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount)//if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount) return Error(Loc.Dic.error_expenses_full_allocation); Budgets_Allocations.CompanyId = CurrentUser.CompanyId; Budgets_Allocations.BudgetId = budget.Id; Budgets_Allocations.CompanyId = CurrentUser.CompanyId; if (allocationsRep.Create(Budgets_Allocations)) return RedirectToAction("Index"); else return Error(Loc.Dic.error_database_error); } else { return Error(Loc.Dic.error_invalid_form); } } else { return Error(Loc.Dic.error_database_error); } } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_database_error); } } } else { return Error(ModelState); } } else { return Error(Loc.Dic.error_no_permission); } }