Exemple #1
0
        public async Task <ActionResultDto <ModuleRunLecturerGroupDto> > AddModuleRunLecturerGroup(ModuleRunLecturerGroupDto moduleRunLecturerGroupDto)
        {
            var moduleRunLecturerGroup = new ModuleRunLecturerGroup();

            mapper.Map(moduleRunLecturerGroupDto, moduleRunLecturerGroup);


            bool containsModelRun = await context.ModuleRunLecturerGroups.ContainsAsync(moduleRunLecturerGroup);

            if (containsModelRun)
            {
                return(new ActionResultDto <ModuleRunLecturerGroupDto>("This group has already been added."));
            }


            var result = await context.ModuleRunLecturerGroups.AddAsync(moduleRunLecturerGroup);

            await context.SaveChangesAsync();

            LecturerGroup lg = new LecturerGroup();

            lg = await context.LecturerGroups.FindAsync(moduleRunLecturerGroup.LecturerGroupId);


            LecturerLecturerGroup llg = new LecturerLecturerGroup();


            var moduleRunId = moduleRunLecturerGroup.ModuleRunId;

            foreach (var l in lg.LecturerLecturerGroup)
            {
                var moduleRunLecturer = new LecturerModuleRun()
                {
                    LecturerId  = l.Lecturer.Id,
                    ModuleRunId = moduleRunId
                };
                bool containsModuleRunLecturer = await context.LecturersModuleRuns.ContainsAsync(moduleRunLecturer);

                if (!containsModuleRunLecturer)
                {
                    context.LecturersModuleRuns.Add(moduleRunLecturer);
                    await context.SaveChangesAsync();
                }
            }
            return(mapper.Map <ModuleRunLecturerGroupDto>(result.Entity));
        }
        public async Task <ActionResultDto <LecturerLecturerGroupDto> > AddLecturerLecturerGroup(LecturerLecturerGroupDto LecturerLecturerGroupDto)
        {
            var LecturerLecturerGroup = new LecturerLecturerGroup();

            _mapper.Map(LecturerLecturerGroupDto, LecturerLecturerGroup);

            if (LecturerLecturerGroup == null)
            {
                return(new ActionResultDto <LecturerLecturerGroupDto>("You can not add an empty lecturer group "));
            }

            bool containsLecturer = await _context.LecturerLecturerGroups.ContainsAsync(LecturerLecturerGroup);

            if (containsLecturer)
            {
                return(new ActionResultDto <LecturerLecturerGroupDto>("Lecturer has already been added."));
            }

            var result = await _context.LecturerLecturerGroups.AddAsync(LecturerLecturerGroup);

            await _context.SaveChangesAsync();

            return(_mapper.Map <LecturerLecturerGroupDto>(result.Entity));
        }