internal static void Update(BudgetVM model, BPARepo bpaRepo) { var budget = bpaRepo.Budget.GetById(model.Id); budget.BudgetName = model.BudgetName; budget.BudgetAmount = model.BudgetAmount; budget.DepartmentId = model.BudgetAmount; budget.ProgramId = model.ProgramId; budget.ActivityId = model.ActivityId; budget.BudgetPeriodId = model.BudgetPeriodId; budget.Months = model.Months; budget.StartDate = model.StartDate; budget.EndDate = model.EndDate; budget.Validate(); var exist = bpaRepo.Budget.GetAll().Any(x => x.BudgetName.Trim().ToLower() == budget.BudgetName.Trim().ToLower() && x.Id != budget.Id); if (!exist) { bpaRepo.Budget.Update(budget); } else { throw new Exception($"{model.BudgetName} already exist"); } }
public static void Create(BudgetVM model, BPARepo bpaRepo) { var budget = new Budget() { BudgetName = model.BudgetName, BudgetAmount = model.BudgetAmount, DepartmentId = model.DepartmentId, ProgramId = model.ProgramId, ActivityId = model.ActivityId, BudgetPeriodId = model.BudgetPeriodId, Months = model.Months, StartDate = model.StartDate, EndDate = model.EndDate, }; budget.Validate(); var exist = bpaRepo.Budget.GetAll().Any(x => x.BudgetName.Trim().ToLower() == budget.BudgetName.Trim().ToLower()); if (!exist) { bpaRepo.Budget.Create(budget); } else { throw new Exception($"{model.BudgetName} already exist"); } }
public static List <BudgetVM> GetAll(BPARepo bpaRepo) { var budgets = bpaRepo.Budget.GetAll().ToList(); var model = new List <BudgetVM>(); foreach (var budget in budgets) { var budgetVM = new BudgetVM() { Id = budget.Id, BudgetName = budget.BudgetName, BudgetAmount = budget.BudgetAmount, DepartmentId = budget.DepartmentId, ProgramId = budget.ProgramId, ActivityId = budget.ActivityId, BudgetPeriodId = budget.BudgetPeriodId, Months = budget.Months, StartDate = budget.StartDate, EndDate = budget.EndDate, }; model.Add(budgetVM); } return(model); }
public async Task <bool> Create(BudgetVM budgetVM) { budgetVM.Start = DateTime.UtcNow; budgetVM.Available = budgetVM.Limit; var budget = this._mapper.Map <Budget>(budgetVM); return(await this._budgetRepository.Create(budget)); }
// GET: Budget public ActionResult Index(Guid userId, int?year, int?month) { var vm = new BudgetVM() { Month = month.Value, Year = year.Value }; return(View(vm)); }
public ActionResult UpdateBudget(BudgetVM model) { try { BudgetServices.Update(model, BPARepo); return(RedirectToAction("Budget")); } catch (Exception ex) { SetViewError(ex); return(View(model)); } }
public async Task <IActionResult> Edit(BudgetVM budgetVM) { if (!ModelState.IsValid) { AddModelErrors(ModelState); ViewData["BudgetPeriods"] = this._periods; return(this.View(budgetVM) .WithDanger("Грешка!", "Моля поправете грешките маркирани с червено.")); } await this._budgetService.Update(budgetVM); return(this.RedirectToAction(nameof(All)) .WithSuccess("Успех!", "Бюджета беше обновен.")); }
public static BudgetVM GetById(int id, BPARepo bpaRepo) { var budget = bpaRepo.Budget.GetById(id); var model = new BudgetVM() { Id = budget.Id, BudgetName = budget.BudgetName, BudgetAmount = budget.BudgetAmount, DepartmentId = budget.DepartmentId, ProgramId = budget.ProgramId, ActivityId = budget.ActivityId, BudgetPeriodId = budget.BudgetPeriodId, Months = budget.Months, StartDate = budget.StartDate, EndDate = budget.EndDate, }; return(model); }
public async Task <IActionResult> Create(BudgetVM budgetVM) { if (!ModelState.IsValid) { AddModelErrors(ModelState); return(this.View(budgetVM) .WithDanger("Грешка!", "Моля поправете грешките маркирани с червено.")); } var user = await this._userService.GetByUsername(User.Identity.Name); budgetVM.UserId = user.Id; if (!await this._budgetService.Create(budgetVM)) { return(this.View(budgetVM)); } return(this.RedirectToAction(nameof(All)) .WithSuccess("Успех!", "Успешно добавихте нов бюджет.")); }
public async Task <bool> Update(BudgetVM budgetVM) { var budget = this._mapper.Map <Budget>(budgetVM); return(await this._budgetRepository.Update(budget)); }