Beispiel #1
0
        public IActionResult Create(BreedViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            BreedServiceModel serviceModel = this.mapper.Map <BreedServiceModel>(model);

            this.breedService.AddBreed(serviceModel);

            return(this.RedirectToAction("All"));
        }
Beispiel #2
0
        public void AddBreed(BreedServiceModel model)
        {
            try
            {
                Breed breed = this.mapper.Map <Breed>(model);

                this.dbContext.Breeds.Add(breed);
                this.dbContext.SaveChanges();
            }
            catch (Exception)
            {
                throw new ArgumentException(ExceptionMessages.InvalidBreed);
            }
        }
Beispiel #3
0
        public void EditBreed(string id, BreedServiceModel model)
        {
            Breed breed = this.mapper.Map <Breed>(model);

            Breed breedToUpdate = this.dbContext
                                  .Breeds
                                  .Find(id);

            if (breedToUpdate == null)
            {
                throw new ArgumentException(ExceptionMessages.InvalidBreed);
            }
            breedToUpdate.Name = breed.Name;

            this.dbContext.SaveChanges();
        }