Beispiel #1
0
        public async Task <IActionResult> Edit(int id, PaymentPlanViewModel view)
        {
            if (id != view.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    PaymentPlan paymentPlan = this.ToPaymentPlan(view);

                    context.Update(paymentPlan);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentPlanExists(view.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), new { id }));
            }

            FillData(ref view);


            return(View(view));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(PaymentPlanViewModel view)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (await CheckBudget(view))
                    {
                        PaymentPlan paymentPlan = this.ToPaymentPlan(view);

                        paymentPlan.ID = 0;

                        context.Add(paymentPlan);
                        await context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Details), new { paymentPlan.ID }));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }

            FillData(ref view);

            return(View(view));
        }
Beispiel #3
0
 private PaymentPlan ToPaymentPlan(PaymentPlanViewModel view)
 {
     return(new PaymentPlan
     {
         ID = view.ID,
         Name = view.Name,
         Description = view.Description,
         Date = view.Date,
         Amount = view.Amount,
         ProjectID = view.ProjectID,
         SolicitanteID = view.SolicitanteID
     });
 }
Beispiel #4
0
        public AllPaymentPlansViewModel GetPaymentPlans(AllPaymentPlansViewModel model, string userId)
        {
            var paymentPlanName  = model.SearchPaymentPlan.Name;
            var sortMethodId     = model.SortMethodId;
            var countBooksOfPage = model.CountPaymentPlanOfPage;
            var currentPage      = model.CurrentPage;

            var plans = this.context.PaymentPlans.Where(p => p.DeletedOn == null)
                        .Select(p => new PaymentPlanViewModel()
            {
                CountBook     = p.CountBook,
                CreatedOn     = p.CreatedOn,
                Id            = p.Id,
                Name          = p.Name,
                PriceOneYear  = p.PriceOneYear,
                PriceTwoYears = p.PriceTwoYears,
                Text          = p.Text,
            });

            plans = this.SelectPlans(paymentPlanName, plans);

            plans = this.SortPlans(sortMethodId, plans);

            int maxCountPage = plans.Count() / countBooksOfPage;

            if (plans.Count() % countBooksOfPage != 0)
            {
                maxCountPage++;
            }

            var viewBook = plans.Skip((currentPage - 1) * countBooksOfPage)
                           .Take(countBooksOfPage);
            var searchPlan = new PaymentPlanViewModel()
            {
                Name = paymentPlanName,
            };

            var returnModel = new AllPaymentPlansViewModel()
            {
                CountPaymentPlanOfPage = countBooksOfPage,
                PaymentPlans           = plans,
                SearchPaymentPlan      = searchPlan,
                SortMethodId           = sortMethodId,
                MaxCountPage           = maxCountPage,
                CurrentPage            = currentPage,
            };

            return(returnModel);
        }
Beispiel #5
0
        private async Task <bool> CheckBudget(PaymentPlanViewModel view)
        {
            Project project = await context.Projects
                              .Include(p => p.PaymentPlans)
                              .Where(p => p.ID == view.ProjectID)
                              .FirstOrDefaultAsync();

            decimal budget = project.PaymentPlans.Sum(p => p.Amount);

            if (budget + view.Amount <= project.BudgetAmount)
            {
                return(true);
            }
            else
            {
                throw new Exception($"Presupuesto excedido. El monto asigado al proyecto es de ${project.BudgetAmount}");
            }
        }
Beispiel #6
0
        private PaymentPlanViewModel ToPaymentPlanViewModel(PaymentPlan paymentPlan)
        {
            var model = new PaymentPlanViewModel()
            {
                ID          = paymentPlan.ID,
                Name        = paymentPlan.Name,
                Description = paymentPlan.Description,
                Date        = paymentPlan.Date,
                Amount      = paymentPlan.Amount,

                SolicitanteID = paymentPlan.SolicitanteID,
                Users         = combosHelper.GetComboUsers(),

                Project     = paymentPlan.Project,
                ProjectName = paymentPlan.Project.Name,
                ProjectID   = paymentPlan.ProjectID
            };

            return(model);
        }
Beispiel #7
0
 private void FillData(ref PaymentPlanViewModel view)
 {
     view.Users = combosHelper.GetComboUsers();
 }