Example #1
0
        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);
        }
Example #2
0
        public ActionResult UpdateBudgetPeriod(BudgetPeriodVM model)
        {
            try
            {
                BudgetPeriodServices.Update(model, BPARepo);

                return(RedirectToAction("BudgetPeriod"));
            }
            catch (Exception ex)
            {
                SetViewError(ex);
                return(View(model));
            }
        }
Example #3
0
        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);
        }
Example #4
0
        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");
            }
        }
Example #5
0
        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");
            }
        }