Exemplo n.º 1
0
        public void Post(FitnessClassDTO value)
        {
            FitnessClass model = new FitnessClass()
            {
                Name = value.Name,
                Img  = value.Img
            };

            IFitnessClassRepository.Create(model); // am creat o clasa

            // trebuie sa introducem si in tabela de intersectie
            for (int i = 0; i < value.InstructorId.Count; i++)
            {
                InstructorFitnessClass InstructorClass = new InstructorFitnessClass()
                {
                    FitnessClassId = model.Id,
                    InstructorId   = value.InstructorId[i]
                };
                IInstructorClassRepository.Create(InstructorClass);
            }

            for (int i = 0; i < value.GymClubId.Count; i++)
            {
                GymClubFitnessClass GymClubClass = new GymClubFitnessClass()
                {
                    FitnessClassId = model.Id,
                    GymClubId      = value.GymClubId[i]
                };
                IGymClubClassRepository.Create(GymClubClass);
            }
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
        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);
        }