public void Put(int id, GymClubDTO value) { GymClub model = IGymClubRepository.Get(id); if (value.Name != null) { model.Name = value.Name; } if (value.AddressId != 0) { model.AddressId = value.AddressId; } IGymClubRepository.Update(model); //trebuie sa putem face update si la lista de artisti si cantece if (value.ClassId != null) { IEnumerable <GymClubFitnessClass> MyGymClubClasses = IGymClubClassRepository.GetAll().Where(x => x.GymClubId == id); foreach (GymClubFitnessClass MyGymClubClass in MyGymClubClasses) { IGymClubClassRepository.Delete(MyGymClubClass); } for (int i = 0; i < value.ClassId.Count; i++) { GymClubFitnessClass GymClubClass = new GymClubFitnessClass() { GymClubId = model.Id, FitnessClassId = value.ClassId[i] }; IGymClubClassRepository.Create(GymClubClass); } } }
public void Put(int id, FitnessClassDTO value) { FitnessClass model = IFitnessClassRepository.Get(id); if (value.Name != null) { model.Name = value.Name; } if (value.Img != null) { model.Img = value.Img; } IFitnessClassRepository.Update(model); //trebuie sa putem face update si la lista de instructori si sali de fitness if (value.InstructorId != null) { IEnumerable <InstructorFitnessClass> MyInstructorClasses = IInstructorClassRepository.GetAll().Where(x => x.FitnessClassId == id); foreach (InstructorFitnessClass MyInstructorClass in MyInstructorClasses) { IInstructorClassRepository.Delete(MyInstructorClass); } for (int i = 0; i < value.InstructorId.Count; i++) { InstructorFitnessClass InstructorClass = new InstructorFitnessClass() { FitnessClassId = model.Id, InstructorId = value.InstructorId[i] }; IInstructorClassRepository.Create(InstructorClass); } } if (value.GymClubId != null) { IEnumerable <GymClubFitnessClass> MyGymClubClasses = IGymClubClassRepository.GetAll().Where(x => x.FitnessClassId == id); foreach (GymClubFitnessClass MyGymClubClass in MyGymClubClasses) { IGymClubClassRepository.Delete(MyGymClubClass); } for (int i = 0; i < value.GymClubId.Count; i++) { GymClubFitnessClass GymClubClass = new GymClubFitnessClass() { FitnessClassId = model.Id, GymClubId = value.GymClubId[i] }; IGymClubClassRepository.Create(GymClubClass); } } }
public FitnessClassDetailsDTO Get(int id) { FitnessClass FitnessClass = IFitnessClassRepository.Get(id); FitnessClassDetailsDTO MyClass = new FitnessClassDetailsDTO() { Name = FitnessClass.Name, Img = FitnessClass.Img }; IEnumerable <InstructorFitnessClass> MyInstructorClasses = IInstructorClassRepository.GetAll().Where(x => x.FitnessClassId == FitnessClass.Id); if (MyInstructorClasses != null) { List <string> InstructorNameList = new List <string>(); foreach (InstructorFitnessClass MyInstructorClass in MyInstructorClasses) { Instructor MyInstructor = IInstructorRepository.GetAll().SingleOrDefault(x => x.Id == MyInstructorClass.InstructorId); InstructorNameList.Add(MyInstructor.FirstName + " " + MyInstructor.LastName); } MyClass.InstructorName = InstructorNameList; } IEnumerable <GymClubFitnessClass> MyGymClubClasses = IGymClubClassRepository.GetAll().Where(x => x.FitnessClassId == FitnessClass.Id); if (MyGymClubClasses != null) { List <string> GymClubNameList = new List <string>(); foreach (GymClubFitnessClass MyGymClubClass in MyGymClubClasses) { GymClub MyGymClub = IGymClubRepository.GetAll().SingleOrDefault(x => x.Id == MyGymClubClass.GymClubId); GymClubNameList.Add(MyGymClub.Name); } MyClass.GymClubName = GymClubNameList; } IEnumerable <Song> MySongs = ISongRepository.GetAll().Where(x => x.FitnessClassId == FitnessClass.Id); if (MySongs != null) { List <string> SongNameList = new List <string>(); foreach (Song MySong in MySongs) { SongNameList.Add(MySong.Name); } MyClass.SongName = SongNameList; } return(MyClass); }