Esempio n. 1
0
        // GET: MilesTypes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            //var milesType = await _context.MilesTypes
            //    .FirstOrDefaultAsync(m => m.Id == id);

            var milesType = await _milesTypeRepository.GetByIdAsync(id.Value);

            if (milesType == null)
            {
                return(NotFound());
            }

            return(View(milesType));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(CreateMileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var client = await _clientRepository
                             .GetClientByNumberAsync(model.MilesProgramNumber);

                if (client == null)
                {
                    ModelState.AddModelError(string.Empty, "Client does not exist");

                    model.MilesType = _combosHelper.GetComboMilesTypes();

                    return(View(model));
                }

                var milesType = await _milesTypeRepository
                                .GetByIdAsync(model.MilesTypeId);

                if (milesType == null)
                {
                    ModelState.AddModelError(string.Empty, "Type does not exist");

                    model.MilesType = _combosHelper.GetComboMilesTypes();

                    return(View(model));
                }

                var mile = _converterHelper.CreateMileViewModelToMile(model, client, milesType);

                await _mileRepository.CreateAsync(mile);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }