public static BudgetPeriodVM GetById(int id, BPARepo bpaRepo) { var budgetPeriod = bpaRepo.BudgetPeriod.GetById(id); var model = new BudgetPeriodVM() { Id = budgetPeriod.Id, Name = budgetPeriod.Name, }; return(model); }
public ActionResult UpdateBudgetPeriod(BudgetPeriodVM model) { try { BudgetPeriodServices.Update(model, BPARepo); return(RedirectToAction("BudgetPeriod")); } catch (Exception ex) { SetViewError(ex); return(View(model)); } }
public static List <BudgetPeriodVM> GetAll(BPARepo bpaRepo) { var budgetPeriods = bpaRepo.BudgetPeriod.GetAll().ToList(); var model = new List <BudgetPeriodVM>(); foreach (var budgetPeriod in budgetPeriods) { var budgetPeriodVM = new BudgetPeriodVM() { Id = budgetPeriod.Id, Name = budgetPeriod.Name, }; model.Add(budgetPeriodVM); } return(model); }
internal static void Update(BudgetPeriodVM model, BPARepo bpaRepo) { var budgetPeriod = bpaRepo.BudgetPeriod.GetById(model.Id); budgetPeriod.Name = model.Name; budgetPeriod.Validate(); var exist = bpaRepo.BudgetPeriod.GetAll().Any(x => x.Name.Trim().ToLower() == budgetPeriod.Name.Trim().ToLower() && x.Id != budgetPeriod.Id); if (!exist) { bpaRepo.BudgetPeriod.Update(budgetPeriod); } else { throw new Exception($"{model.Name} already exist"); } }
public static void Create(BudgetPeriodVM model, BPARepo bpaRepo) { var budgetPeriod = new BudgetPeriod() { Name = model.Name, }; budgetPeriod.Validate(); var exist = bpaRepo.BudgetPeriod.GetAll().Any(x => x.Name.Trim().ToLower() == budgetPeriod.Name.Trim().ToLower()); if (!exist) { bpaRepo.BudgetPeriod.Create(budgetPeriod); } else { throw new Exception($"{model.Name} already exist"); } }