Ejemplo n.º 1
0
        public async Task <bool> UpdateExamSession(ExamSessionDto examSessionDto)
        {
            var examSession = await MapFromDto(examSessionDto);

            if (examSession == null)
            {
                return(false);
            }
            try
            {
                _context.Update(examSession);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExamSessionExists(examSessionDto.Id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        Create([Bind("Id,Name,Description,StartDate,EndDate,ExamSiteId")] ExamSessionDto examSessionDto)
        {
            if (ModelState.IsValid)
            {
                _examSessionService.SaveNewExamSession(examSessionDto);

                return(RedirectToAction(nameof(Index)));
            }

            //TODO Toast Notification: Update Failed

            return(View(await _examSessionService.ReturnPopulatedExamSessionFormDto(examSessionDto)));
        }
Ejemplo n.º 3
0
        public async Task <ExamSessionFormVM> ReturnPopulatedExamSessionFormDto(
            ExamSessionDto examSessionDto)
        {
            var examSites = await _context.ExamSites.ToListAsync();

            var examSessionFormVM = new ExamSessionFormVM
            {
                ExamSessionDto = examSessionDto,
                ExamSites      = examSites
            };

            return(examSessionFormVM);
        }
Ejemplo n.º 4
0
        private ExamSessionDto MapToDto(ExamSession examSession)
        {
            var examSessionDto = new ExamSessionDto
            {
                Id          = examSession.Id,
                Description = examSession.Description,
                Name        = examSession.Name,
                EndDate     = examSession.EndDate,
                StartDate   = examSession.StartDate,
                ExamSiteId  = examSession.ExamSite.Id
            };

            return(examSessionDto);
        }
Ejemplo n.º 5
0
        Edit(int id, [Bind("Id,Name,Description,StartDate,EndDate,ExamSiteId")] ExamSessionDto examSessionDto)
        {
            if (id != examSessionDto.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (await _examSessionService.UpdateExamSession(examSessionDto))
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(NotFound());
                }
            }
            return(View(await _examSessionService.ReturnPopulatedExamSessionFormDto(examSessionDto)));
        }
Ejemplo n.º 6
0
        private async Task <ExamSession> MapFromDto(ExamSessionDto examSessionDto)
        {
            var examSite = await _context.ExamSites
                           .FirstOrDefaultAsync(e => e.Id == examSessionDto.ExamSiteId);

            if (examSite != null)
            {
                var examSession = new ExamSession
                {
                    Id          = examSessionDto.Id,
                    Description = examSessionDto.Description,
                    Name        = examSessionDto.Name,
                    EndDate     = examSessionDto.EndDate,
                    StartDate   = examSessionDto.StartDate,
                    ExamSite    = examSite
                };
                return(examSession);
            }
            return(null);
        }
Ejemplo n.º 7
0
 public async void SaveNewExamSession(ExamSessionDto examSessionDto)
 {
     _context.Add(await MapFromDto(examSessionDto));
     await _context.SaveChangesAsync();
 }