public void SaveNewDog(DogFM fm) { Dog dog = new Dog(); dog.Name = fm.Name; dog.Age = fm.Age; using (UnitOfWork uow = new UnitOfWork()) { Breed breed = uow.GetBreedDAO().GetBreedById(fm.BreedId); uow.GetDogDAO().CreateDog(dog, breed); } }
public void UpdateDog(DogFM fm) { using (UnitOfWork uow = new UnitOfWork()) { Dog dog = uow.GetDogDAO().GetDogById(fm.Id); dog.Name = fm.Name; dog.Age = fm.Age; uow.GetDogDAO().UpdateDog(dog); Breed breed = uow.GetBreedDAO().GetBreedById(fm.BreedId); uow.GetDogDAO().UpdateDogBreed(dog, breed); } }
private List <BreedVM> GetBreedVMs(UnitOfWork uow) { List <BreedVM> breeds = new List <BreedVM>(); foreach (Breed breed in uow.GetBreedDAO().GetAllBreeds()) { BreedVM breedVM = new BreedVM(); breedVM.Id = breed.Id; breedVM.Type = breed.Type; breeds.Add(breedVM); } return(breeds); }
public DogsVM GetDogsVM() { DogsVM vm = new DogsVM(); using (UnitOfWork uow = new UnitOfWork()) { foreach (Dog dog in uow.GetDogDAO().GetAllDogs()) { ViewDogVM dogVM = new ViewDogVM(); dogVM.Id = dog.Id; dogVM.Age = dog.Age; dogVM.Name = dog.Name; dogVM.Breed = uow.GetBreedDAO().GetBreedByDog(dog).Type; vm.Dogs.Add(dogVM); } } return(vm); }
public EditDogVM GetEditDogVM(int id) { EditDogVM vm = new EditDogVM(); using (UnitOfWork uow = new UnitOfWork()) { vm.Breeds = GetBreedVMs(uow); DogVM dogVM = new DogVM(); Dog dog = uow.GetDogDAO().GetDogById(id); dogVM.Id = id; dogVM.Age = dog.Age; dogVM.Name = dog.Name; BreedVM breedVM = new BreedVM(); Breed breed = uow.GetBreedDAO().GetBreedByDog(dog); breedVM.Id = breed.Id; breedVM.Type = breed.Type; vm.Dog = dogVM; vm.Breed = breedVM; } return(vm); }