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