Пример #1
0
        public ActionResult Create(TariffViewModel tariff)
        {
            tariff.PmtFrequency = 1;
            if (tariff.MinAge > tariff.MaxAge)
            {
                ModelState.AddModelError("MinAge", "Minimal age is greater than maximal");
            }
            if (tariff.MinAmount > tariff.MaxAmount)
            {
                ModelState.AddModelError("MinAmount", "Minimal loan amount is greater than maximal");
            }
            if (tariff.MinTerm > tariff.MaxTerm)
            {
                ModelState.AddModelError("MinTerm", "Minimal term is greater than maximal");
            }
            if (Service.GetTariffs().Any(t => t.Name.ToLower() == tariff.Name.ToLower()))
            {
                ModelState.AddModelError("Name", "There is already tariff with equal name");
            }
            if (ModelState.IsValid)
            {
                tariff.CreationDate = Service.GetCurrentDate();
                Service.UpsertTariff(tariff.Convert());
                return(RedirectToAction("Index"));
            }

            return(View(tariff));
        }
Пример #2
0
        public ActionResult Edit(TariffViewModel tariff)
        {
            tariff.PmtFrequency = 1;
            if (tariff.MinAge > tariff.MaxAge)
            {
                ModelState.AddModelError("MinAge", "Minimal age is greater than maximal");
            }
            if (tariff.MinAmount > tariff.MaxAmount)
            {
                ModelState.AddModelError("MinAmount", "Minimal loan amount is greater than maximal");
            }
            if (tariff.MinTerm > tariff.MaxTerm)
            {
                ModelState.AddModelError("MinTerm", "Minimal term is greater than maximal");
            }
            if (ModelState.IsValid)
            {
                Service.UpsertTariff(tariff.Convert());
                return(RedirectToAction("Index"));
            }
            var id = tariff.Id;

            ViewBag.CanBeEdited = !Service.GetLoans().Any(l => l.Application.TariffId == id) &&
                                  !Service.GetLoanApplications().Any(la => la.TariffId == id);
            return(View(tariff));
        }