public async Task <ActionResult <ClassPeriod> > CreateClassPeriod(ClassPeriod classPeriod)
        {
            _logger.LogInformation("Creating Class Period {@ClassPeriod} at {RequestTime}", classPeriod, DateTime.UtcNow);

            try
            {
                classPeriod = await _service.CreateAsync(classPeriod.Name);

                return(CreatedAtAction(
                           nameof(GetClassPeriod),
                           new { id = classPeriod.Id },
                           classPeriod
                           ));
            }
            catch (DuplicateClassPeriodException ex)
            {
                ModelState.AddModelError(nameof(classPeriod.Name), ex.Message);
                return(BadRequest(ModelState)); // TODO: return ValidationProblem instead?
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Creating Class Period {@ClassPeriod} failed", classPeriod);
            }

            return(StatusCode((int)HttpStatusCode.InternalServerError));
        }
Exemplo n.º 2
0
 /**Given**/
 protected async Task <ClassPeriod> GivenIPreviouslyCreatedClassPeriod(string name)
 => await _sut.CreateAsync(name);