public async Task CreateAsync(AddPetInputModel input) { var user = new ApplicationUser { UserName = input.EmaiAddress, PhoneNumber = input.PhoneNumber, }; this.userService.CreateUserAsync(user.UserName); var pet = new Pet { AnimalTypeId = input.AnimalTypeId, AnimalBreedId = input.AnimalBreedId, Age = input.Age, Name = input.Name, Gender = input.Gender, DoctorId = input.DoctorId, PetOwner = currentPetOwner, }; await this.petRepository.AddAsync(pet); await this.petRepository.SaveChangesAsync(); }
public async Task AddAsync(AddPetInputModel input, int specieId, string userId, List <string> imagePaths) { var images = new List <Image>(); foreach (var imagePath in imagePaths) { var image = new Image() { Url = imagePath, AddedByUserId = userId, PetId = input.Id, }; images.Add(image); } string genderAsString = input.Gender; Gender gender = (Gender)Enum.Parse(typeof(Gender), genderAsString); var pet = new Pet() { AddedByUserId = userId, BreedId = input.BreedId, Name = input.Name, Gender = gender, DateOfBirth = input.DateOfBirth, CityId = input.CityId, SpecieId = specieId, Images = images, }; await this.petsRepository.AddAsync(pet); await this.petsRepository.SaveChangesAsync(); }
public async Task CreatePetOwnerAsync(AddPetInputModel input) { var userManager = this.service.GetRequiredService <UserManager <ApplicationUser> >(); string password = this.GeneratePassword(input.EmailAddress); var user = new ApplicationUser { UserName = input.EmailAddress, Email = input.EmailAddress, }; IdentityResult result = new IdentityResult(); result = userManager.CreateAsync(user, password).Result; if (result.Succeeded) { await userManager.AddToRoleAsync(user, GlobalConstants.PetOwnerRoleName); } else { throw new ArgumentException(string.Format(Common.ErrorMessages.UserIsNotInDesiredRole, user, Common.GlobalConstants.PetOwnerRoleName)); } user.PetOwner = new PetOwner { ApplicationUserId = user.Id, EmailAddress = user.Email, }; await this.userRepositiry.SaveChangesAsync(); await this.ownerRepository.SaveChangesAsync(); }
public async Task AddingAsyncAPetTestAndGetCount() { var list = new List <Pet>(); var mockRepo = new Mock <IDeletableEntityRepository <Pet> >(); mockRepo.Setup(x => x.All()).Returns(list.AsQueryable()); mockRepo.Setup(x => x.AddAsync(It.IsAny <Pet>())) .Callback( (Pet pet) => list.Add(pet)); var service = new PetsService(mockRepo.Object); var inputModel = new AddPetInputModel { BreedId = 1, CityId = 1, Id = 1, Name = "Gosho", DateOfBirth = new DateTime(2008, 3, 1, 7, 0, 0), Gender = "Male", }; var imagePaths = new List <string>(); imagePaths.Add("vasko.com"); await service.AddAsync(inputModel, 1, "Pesho", imagePaths); Assert.Equal(1, service.GetCount()); }
public IActionResult Add(int specieId) { var viewModel = new AddPetInputModel(); viewModel.Breeds = this.breedsService.GetAllAsKeyValuePairs(specieId); viewModel.Cities = this.citiesService.GetAllAsKeyValuePairs(); return(this.View(viewModel)); }
public IActionResult RegisterPet() { var model = new AddPetInputModel(); model.AnimalTypes = this.animalTypeSevice.GetAllAnimalTypes(); model.AnimalBreeds = this.breedService.GetAllAnimalBreeds(); model.Doctors = this.doctorService.GetAllDoctorsFirstAndLastName(); return(this.View(model)); }
public async Task <IActionResult> RegisterPet(AddPetInputModel input) { if (!this.ModelState.IsValid) { input.AnimalTypes = this.animalTypeSevice.GetAllAnimalTypes(); input.AnimalBreeds = this.breedService.GetAllAnimalBreeds(); input.Doctors = this.doctorService.GetAllDoctorsFirstAndLastName(); return(this.View(input)); } await this.petService.CreateAsync(input); return(this.RedirectToAction(nameof(this.Index))); }
public async Task <IActionResult> Add(AddPetInputModel input, int specieId) { if (!this.ModelState.IsValid) { input.Breeds = this.breedsService.GetAllAsKeyValuePairs(specieId); input.Cities = this.citiesService.GetAllAsKeyValuePairs(); return(this.View(input)); } ApplicationUser user = await this.userManager.GetUserAsync(this.User); var result = await CloudinaryExtentsion.UploadAsync(this.cloudinary, input.Images); await this.petsService.AddAsync(input, specieId, user.Id, result); return(this.Redirect($"/Users/MyPets?addedByUserId={user.Id}")); }
public async Task CreateAsync(AddPetInputModel input) { await this.userService.CreatePetOwnerAsync(input); var currentAppUser = this.userRepository .AllAsNoTracking() .FirstOrDefault(x => x.UserName == input.EmailAddress); var pet = new Pet { AnimalTypeId = input.AnimalTypeId, AnimalBreedId = input.AnimalBreedId, Age = input.Age, Name = input.Name, Gender = input.Gender, DoctorId = input.DoctorId, }; var currentPetOwner = this.ownerRepository .All() .FirstOrDefault(x => x.ApplicationUser == currentAppUser); await this.petRepository.AddAsync(pet); await this.petRepository.SaveChangesAsync(); currentPetOwner.Pets.Add(pet); await this.ownerRepository.SaveChangesAsync(); var currentDoctor = this.doctorRepository .AllAsNoTracking() .FirstOrDefault(x => x.Id == input.DoctorId); currentDoctor.Pets.Add(pet); await this.doctorRepository.SaveChangesAsync(); }