示例#1
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;
                if (model.Photo != null && model.Photo.Length > 0)
                {
                    path = await _imageHelper.UploadImageAsync(model.Photo, "Animals");
                }

                var animal = _converterHelper.ToAnimalEntity(model, path);
                await _animalRepository.CreateAsync(animal);

                return(RedirectToAction(nameof(Index), new { id = model.OwnerId }));
            }

            model.Species = _comboHelper.GetComboSpecies();
            model.Breeds  = await _comboHelper.GetComboBreedsAsync(model.SpecieId);

            return(View(model));
        }