public ActionResult Import(HttpPostedFileBase file, int?id, string name, int?year, string budgetType) { if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } if (file != null && file.ContentLength <= 0) { return(Error(Loc.Dic.error_invalid_form)); } if (string.IsNullOrEmpty(budgetType)) { return(Error(Loc.Dic.Error_chooseMonthelyOrYearlyBudget)); } if (!(budgetType == "Month" || budgetType == "Year")) { return(Error(Loc.Dic.Error_no_budgetType)); } if (id.HasValue) { string moved = Interfaces.ImportBudget(file.InputStream, CurrentUser.CompanyId, id.Value, budgetType); if (moved == "OK") { return(RedirectToAction("index")); } else { return(Error(moved)); } } else if (year.HasValue) { if (year.Value > DateTime.Now.Year + 10 || year.Value < DateTime.Now.Year - 1) { return(Error(Loc.Dic.error_invalid_budget_year)); } using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) { Budget newBudget = new Budget(); newBudget.Name = name; newBudget.Year = year.Value; newBudget.CompanyId = CurrentUser.CompanyId; newBudget.IsActive = false; budgetsRepository.Create(newBudget); string moved = Interfaces.ImportBudget(file.InputStream, CurrentUser.CompanyId, newBudget.Id, budgetType); if (moved == "OK") { return(RedirectToAction("index")); } else { return(Error(moved)); } } } return(Error(Loc.Dic.error_invalid_form)); }
public ActionResult Create(Budget budget) { if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { if (budget.Year >= DateTime.Now.Year) { budget.CompanyId = CurrentUser.CompanyId; budget.IsActive = false; bool wasCreated; using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) { bool yearExists = budgetRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Year == budget.Year); if (yearExists) { return(Error(Loc.Dic.error_budgets_year_exists)); } wasCreated = budgetRep.Create(budget); } if (wasCreated) { return(RedirectToAction("Index")); } else { return(Error(Loc.Dic.error_budgets_create_error)); } } else { return(Error(Loc.Dic.error_budgets_year_passed)); } } else { return(Error(ModelState)); } } else { return(Error(Loc.Dic.error_no_permission)); } }
public ActionResult Import(HttpPostedFileBase file, int? id, string name, int? year, string budgetType) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); if (file != null && file.ContentLength <= 0) return Error(Loc.Dic.error_invalid_form); if (string.IsNullOrEmpty(budgetType)) return Error(Loc.Dic.Error_chooseMonthelyOrYearlyBudget); if (!(budgetType == "Month" || budgetType == "Year")) return Error(Loc.Dic.Error_no_budgetType); if (id.HasValue) { string moved = Interfaces.ImportBudget(file.InputStream, CurrentUser.CompanyId, id.Value, budgetType); if (moved == "OK") return RedirectToAction("index"); else return Error(moved); } else if (year.HasValue) { if (year.Value > DateTime.Now.Year + 10 || year.Value < DateTime.Now.Year - 1) return Error(Loc.Dic.error_invalid_budget_year); using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId)) { Budget newBudget = new Budget(); newBudget.Name = name; newBudget.Year = year.Value; newBudget.CompanyId = CurrentUser.CompanyId; newBudget.IsActive = false; budgetsRepository.Create(newBudget); string moved = Interfaces.ImportBudget(file.InputStream, CurrentUser.CompanyId, newBudget.Id, budgetType); if (moved == "OK") return RedirectToAction("index"); else return Error(moved); } } return Error(Loc.Dic.error_invalid_form); }
public ActionResult Create(Budget budget) { if (Authorized(RoleType.SystemManager)) { if (ModelState.IsValid) { if (budget.Year >= DateTime.Now.Year) { budget.CompanyId = CurrentUser.CompanyId; budget.IsActive = false; bool wasCreated; using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId)) { bool yearExists = budgetRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Year == budget.Year); if (yearExists) return Error(Loc.Dic.error_budgets_year_exists); wasCreated = budgetRep.Create(budget); } if (wasCreated) return RedirectToAction("Index"); else return Error(Loc.Dic.error_budgets_create_error); } else { return Error(Loc.Dic.error_budgets_year_passed); } } else { return Error(ModelState); } } else { return Error(Loc.Dic.error_no_permission); } }