Exemple #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);
            }
        }
Exemple #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);
                }
            }
        }