Beispiel #1
0
        public async Task <IActionResult> AddImage(PetImageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile);
                }

                var petImage = new PetImage
                {
                    ImageUrl = path,
                    Pet      = await _context.Pets.FindAsync(model.Id)
                };

                _context.PetImages.Add(petImage);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"{nameof(DetailsPet)}/{model.Id}"));
            }

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> AddImage(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var pet = await _context.Pets.FindAsync(id.Value);

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

            var model = new PetImageViewModel
            {
                Id = pet.Id
            };

            return(View(model));
        }