コード例 #1
0
        public IActionResult DeleteAbsence(int id)
        {
            var absence    = _absencesService.GetById <AbsenceInputModel>(id);
            var inputModel = new AbsenceModifyInputModel()
            {
                Id      = id,
                Absence = absence
            };

            return(View(inputModel));
        }
コード例 #2
0
        public async Task EditAsync(AbsenceModifyInputModel modifiedModel)
        {
            var absence = _absencesRepository.All().FirstOrDefault(a => a.Id == modifiedModel.Id);

            if (absence != null)
            {
                var inputModel = modifiedModel.Absence;
                absence.Period = inputModel.Period;
                absence.Type   = inputModel.Type;

                _absencesRepository.Update(absence);
                await _absencesRepository.SaveChangesAsync();
            }
        }
コード例 #3
0
        public async Task EditAbsenceAsyncTest_HappyPath()
        {
            OneTimeSetUp();
            var absence    = _absencesRepositoryMock.Object.All().FirstOrDefault();
            var newAbsence = new AbsenceModifyInputModel()
            {
                Id      = absence.Id,
                Absence = new AbsenceInputModel()
                {
                    StudentId = absence.StudentSubject.StudentId,
                    Period    = AbsencePeriod.SecondTerm,
                    Type      = AbsenceType.OneThird,
                },
            };

            await _absencesService.EditAsync(newAbsence);

            absence.Should().NotBe(newAbsence);
        }
コード例 #4
0
        public async Task <IActionResult> DeleteAbsence(AbsenceModifyInputModel inputModel, string onSubmitAction)
        {
            if (onSubmitAction.IsNullOrEmpty() || onSubmitAction == "Cancel")
            {
                return(RedirectToAction("SubjectsList", "Subjects", new { area = string.Empty }));
            }

            try
            {
                await _absencesService.DeleteAsync(inputModel.Id);

                return(RedirectToAction("SubjectsList", "Subjects", new { area = string.Empty }));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An exception occured during student DELETE operation for absence with id {inputModel.Id}. Ex: {e.Message}");
                return(RedirectToAction("Error", "Home"));
            }
        }
コード例 #5
0
        public async Task <IActionResult> EditAbsence(AbsenceModifyInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(inputModel));
            }

            try
            {
                await _absencesService.EditAsync(inputModel);

                return(RedirectToAction("SubjectsList", "Subjects", new { area = string.Empty }));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An exception occured during student UPDATE operation for absence with id {inputModel.Id}. Ex: {e.Message}");
                return(RedirectToAction("Error", "Home"));
            }
        }