public async Task <ActionResult <GenericResponse <string> > > Post(SomeRequest request) { // validate var r = await _someValidator.ValidateAsync(request); // convert to generic response var result = r.ToGenericResponse <string>(); if (!result.IsValid) { // return 400 return(BadRequest(result)); } try { // service call result = await _someService.CreateAsync(request); // return 201 return(Created(new Uri($"https://some.domain-com/path/{result.Id}"), result)); } catch (Exception ex) { _logger.LogError(ex, "POST error: {0}, stack:", ex.Message, ex.StackTrace); result.Errors.Add(new ErrorItem(ex.Message, ex.StackTrace)); // return 500 return(StatusCode(500, result)); } }
public async Task <GenericResponse <string> > CreateAsync(SomeRequest request) { var r = new GenericResponse <string>(); r.Id = Guid.NewGuid().ToString("N").Substring(0, 8); return(await Task.FromResult(r)); }