public async Task <IActionResult> Create(CreateAnimalInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.CategoriesItems = this.categoriesService.GetAllKeyValuePairs();

                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            ////var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; info from cookie

            // create animal using service method
            try
            {
                await this.animalService.CreateAsync(input, user.Id);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View(input));
            }

            // todo redirect to animal info page
            return(this.Redirect("/Animal/All"));
        }
        public async Task CreateAsync(CreateAnimalInputModel input, string userId)
        {
            var extension = Path.GetExtension(input.Image.FileName);

            if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
            {
                throw new Exception($"Invalid image extension {extension}");
            }

            var imageUrl = await this.cloudinaryService.UploadAsync(this.cloudinary, input.Image);

            var animal = new Animal
            {
                UserId     = userId,
                CategoryId = input.CategoryId,
                Name       = input.Name,
                Age        = input.Age,
                Color      = input.Color,
                Weight     = input.Weight,
                ImageUrl   = imageUrl,
            };

            await this.animalsRepository.AddAsync(animal);

            await this.animalsRepository.SaveChangesAsync();
        }
        public IActionResult Create()
        {
            var viewModel = new CreateAnimalInputModel();

            viewModel.CategoriesItems = this.categoriesService.GetAllKeyValuePairs();

            return(this.View(viewModel));
        }