Ejemplo n.º 1
0
        public void CreatePost(CreatePostModel createPostModel, int userId)
        {
            var locationId   = locationServices.GetLocationIdByLocationName(context, createPostModel.LocationName);
            var animalTypeId = animalTypeServices.GetAnimalTypeIdByAnimalTypeName(context, createPostModel.AnimalTypeName);
            var breedTypeId  = breedTypeServices.GetBreedTypeIdByBreedTypeName(createPostModel.BreedTypeName);

            var animal = new Animal
            {
                AnimalName   = createPostModel.AnimalName,
                Birthday     = createPostModel.Birthday,
                AnimalTypeId = animalTypeId,
                BreedTypeId  = breedTypeId,
                LocationId   = locationId,
                UserId       = userId
            };

            var postToCreate = AutoMapper.Mapper.Map <Post>(createPostModel);

            postToCreate.Animal = animal;
            postToCreate.User   = context.Users.Find(userId);

            this.context.Posts.Add(postToCreate);
            this.context.SaveChanges();
        }
Ejemplo n.º 2
0
 public void Throw_ArgumentException_When_Executed_With_UnexistentBreedTypeName()
 {
     //Act & Assert
     Assert.ThrowsException <ArgumentException>(() => breedTypeServices.GetBreedTypeIdByBreedTypeName("Brontozav"));
 }