Пример #1
0
        public IActionResult EditTariff(int?id)
        {
            if (id != null)
            {
                var model = _tariffService.GetById((int)id);
                if (model is null)
                {
                    return(View("SomethingWentWrong", "on getting tariff by id"));
                }

                model.AllOptions      = _tariffOptionDescriptionService.GetAll();
                model.AssignedOptions = _tariffOptionsService.GetAllOptionsAssignedToATariffById((int)id);
                return(View(model));
            }

            return(View("EditTariff", new EditTariffViewModel()));
        }
Пример #2
0
        public EditTariffViewModel GetById(int id)
        {
            var tariff = _context.Tariffs.FirstOrDefault(x => x.Id == id);

            if (tariff is null)
            {
                return(null);
            }

            return(new EditTariffViewModel
            {
                Id = tariff.Id,
                Name = tariff.Name,
                Price = tariff.Price,
                DaysActive = tariff.DaysActive,
                Description = tariff.Description,
                AllOptions = _tariffOptionDescriptionService.GetAll(),
                AssignedOptions = _tariffOptionsService.GetAllOptionsAssignedToATariffById(id)
            });
        }