public async Task <IActionResult> Add([FromBody] NewRegulationModel model) { if (!ModelState.IsValid) { return(BadRequest(ErrorResponse.Create("Invalid model.", ModelState))); } var regulation = Mapper.Map <Core.Domain.Regulation>(model); try { await _regulationService.AddAsync(regulation); } catch (ServiceException exception) { _log.Error(nameof(Add), exception, $"{nameof(model)}: {model.ToJson()}. IP: {HttpContext.GetIp()}"); return(BadRequest(ErrorResponse.Create(exception.Message))); } _log.Info(nameof(Add), $"Regulation added. {nameof(model)}: {model.ToJson()}. IP: {HttpContext.GetIp()}", model.Id); return(NoContent()); }
/// <summary> /// Adds the regulation. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='model'> /// The model what describe a regulation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ErrorResponse> AddRegulationAsync(this IRegulationAPI operations, NewRegulationModel model = default(NewRegulationModel), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.AddRegulationWithHttpMessagesAsync(model, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Adds the regulation. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='model'> /// The model what describe a regulation. /// </param> public static ErrorResponse AddRegulation(this IRegulationAPI operations, NewRegulationModel model = default(NewRegulationModel)) { return(operations.AddRegulationAsync(model).GetAwaiter().GetResult()); }