Esempio n. 1
0
        public async Task UpdateAsync(MissedClass missedClass)
        {
            var lectureToUpdate = await GetByIdAsync(missedClass.Id);

            if (missedClass == null)
            {
                throw new BusinessLogicException(nameof(missedClass));
            }

            var student = await _students.GetByIdAsync(missedClass.StudentId);

            if (student == null)
            {
                throw new BusinessLogicException("Student not found");
            }

            var lesson = await _classes.GetByIdAsync(missedClass.ClassId);

            if (lesson == null)
            {
                throw new BusinessLogicException("Class not found");
            }

            var dto = _mapper.Map <MissedLecturesDto>(missedClass);
            await _missedClasses.UpdateAsync(dto);
        }
        public async Task <IActionResult> Update(MissedClassManageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var missedClass = new MissedClass
                {
                    ClassId   = model.ClassId,
                    StudentId = model.StudentId,
                };

                try
                {
                    await _missedClassesFacade.UpdateAsync(missedClass);

                    _logger.LogInformation("Updated missed class");

                    return(RedirectToAction(nameof(List)));
                }
                catch (BusinessLogicException ex)
                {
                    _logger.LogError(ex.Message);
                    var error = new ErrorViewModel
                    {
                        ErrorMessage = ex.Message,
                        ReturnUrl    = Request.GetReferer(),
                    };

                    return(View("Error", error));
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Update([FromBody] MissedClass missedClass)
        {
            try
            {
                await _missedClassService.UpdateAsync(missedClass);

                _logger.LogInformation("Added new class");

                return(Ok());
            }
            catch (BusinessLogicException ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
 public async Task UpdateAsync(MissedClass model) => await _missedClassesApi.UpdateAsync(model);
 public async Task AddAsync(MissedClass model) => await _missedClassesApi.AddAsync(model);