Beispiel #1
0
        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");
            }
        }
Beispiel #2
0
        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");
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        // 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));
            }
        }
Beispiel #7
0
        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("Успех!", "Бюджета беше обновен."));
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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("Успех!", "Успешно добавихте нов бюджет."));
        }
Beispiel #10
0
        public async Task <bool> Update(BudgetVM budgetVM)
        {
            var budget = this._mapper.Map <Budget>(budgetVM);

            return(await this._budgetRepository.Update(budget));
        }