Пример #1
0
        public async Task <GetPlanningSectionResourceDown> CreatePlannings(SetPlanningSectionResource planningSectionResource)
        {
            var planningGroupe  = new PlanningGroupe();
            var planningSGroupe = new PlanningSGroupe();
            var sections        = await _planningRepository.GetFullBySectionId(planningSectionResource.SectionId);

            planningSectionResource.LastUpdate = DateTime.Now;
            var planingSection = _mapper.Map <SetPlanningSectionResource, PlanningSection>(planningSectionResource);

            _sectionRepository.Add(planingSection);
            await _unitOfWork.CompleteAsync();

            //Create Planning to each Groupe
            foreach (var groupeItem in sections.Groupes)
            {
                planningGroupe = new PlanningGroupe
                {
                    GroupeId          = groupeItem.Id,
                    PlanningSectionId = planingSection.Id,
                    LastUpdate        = DateTime.Now
                };
                _groupeRepository.Add(planningGroupe);
                await _unitOfWork.CompleteAsync();

                //Create Planning to each Sous-Groupe
                foreach (var sGroupItem in groupeItem.SousGroupes)
                {
                    planningSGroupe = new PlanningSGroupe
                    {
                        PlanningGroupeId = planningGroupe.Id,
                        SousGroupeId     = sGroupItem.Id,
                        LastUpdate       = DateTime.Now
                    };
                    _sGroupeRepository.Add(planningSGroupe);
                    await _unitOfWork.CompleteAsync();
                }
            }

            return(_mapper.Map <PlanningSection, GetPlanningSectionResourceDown>(planingSection));
        }