public IActionResult Update([FromBody] Contact value, Guid id) { value.Id = id; return(new WebApiPut <Contact>(this, () => Manager.UpdateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null)); }
/// <summary> /// Invokes the <see cref="WebApiExceptionHandlerMiddleware"/>. /// </summary> /// <param name="context">The <see cref="HttpContext"/>.</param> /// <returns>The <see cref="Task"/>.</returns> public async Task InvokeAsync(HttpContext context) { try { await _next(context).ConfigureAwait(false); } #pragma warning disable CA1031 // Do not catch general exception types; by-design, is intended to catch *any* unhandled exception. catch (Exception ex) { var ac = new ActionContext(context, new RouteData(), new ActionDescriptor()); var ar = WebApiActionBase.CreateResultFromException(ac, ex); if (ar == null) { ar = new ObjectResult(IncludeUnhandledExceptionInResponse ? ex.ToString() : UnhandledExceptionMessage) { StatusCode = (int)UnhandledExceptionStatusCode }; Beef.Diagnostics.Logger.Default.Exception(ex, UnhandledExceptionMessage); } await ar.ExecuteResultAsync(ac).ConfigureAwait(false); } #pragma warning restore CA1031 }
/// <summary> /// Provides a standardised approach to handle an unhandled <see cref="Exception"/>. /// </summary> /// <param name="builder">The <see cref="IApplicationBuilder"/>.</param> /// <param name="includeExceptionInError">Indicates whether to include the <see cref="Exception"/> details in the resulting error.</param> public static void ExceptionHandler(IApplicationBuilder builder, bool includeExceptionInError = false) { Check.NotNull(builder, nameof(builder)); builder.Run(async context => { var ex = context.Features.Get <IExceptionHandlerFeature>(); if (ex != null) { var ac = new ActionContext(context, new RouteData(), new ActionDescriptor()); var ar = WebApiActionBase.CreateResultFromException(ac, ex.Error); if (ar == null) { ar = new ObjectResult(includeExceptionInError ? ex.Error.ToString() : UnhandledExceptionMessage) { StatusCode = (int)UnhandledExceptionStatusCode }; Logger.Default.Exception(ex.Error, UnhandledExceptionMessage); } await ar.ExecuteResultAsync(ac); } }); }
public IActionResult Update([FromBody] Gender value, Guid id) => new WebApiPut <Gender>(this, () => _manager.UpdateAsync(WebApiActionBase.Value(value), id), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null);
public IActionResult Create([FromBody] Gender value) => new WebApiPost <Gender>(this, () => _manager.CreateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null);
public IActionResult Update([FromBody] PerformanceReview value, Guid id) { return(new WebApiPut <PerformanceReview>(this, () => _manager.UpdateAsync(WebApiActionBase.Value(value), id), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null)); }
public IActionResult Create([FromBody] PerformanceReview value, Guid employeeId) { return(new WebApiPost <PerformanceReview>(this, () => _manager.CreateAsync(WebApiActionBase.Value(value), employeeId), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null)); }
public IActionResult Create([FromBody] Robot value) { return(new WebApiPost <Robot>(this, () => Factory.Create <IRobotManager>().CreateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null)); }
public IActionResult Terminate([FromBody] TerminationDetail value, Guid id) => new WebApiPost <Employee>(this, () => _manager.TerminateAsync(WebApiActionBase.Value(value), id), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null);
public IActionResult CreateWithEf([FromBody] Person value) { return(new WebApiPost <Person>(this, () => Factory.Create <IPersonManager>().CreateWithEfAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null)); }
public IActionResult Create([FromBody] Person value) { return(new WebApiPost <Person>(this, () => _manager.CreateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null)); }
public IActionResult Create([FromBody] PerformanceReview value, Guid employeeId) => new WebApiPost <PerformanceReview>(this, () => _manager.CreateAsync(WebApiActionBase.Value(value), employeeId), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null, locationUri: (r) => new Uri($"/api/v1/reviews/{r.Id}", UriKind.Relative));
public IActionResult UpdateWithRollback([FromBody] Person value, Guid id) => new WebApiPut <Person>(this, () => _manager.UpdateWithRollbackAsync(WebApiActionBase.Value(value), id), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null);
public IActionResult Create([FromBody] Person value) => new WebApiPost <Person>(this, () => _manager.CreateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null, locationUri: (r) => new Uri($"/api/v1/persons/{r.Id}", UriKind.Relative));
public IActionResult EventPublishNoSend([FromBody] Person value) => new WebApiPut <Person>(this, () => _manager.EventPublishNoSendAsync(WebApiActionBase.Value(value)), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null);
public IActionResult Create(Contact value) { return(new WebApiPost <Contact>(this, () => Manager.CreateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null)); }
public IActionResult Update([FromBody] TripPerson value, string?id) => new WebApiPut <TripPerson>(this, () => _manager.UpdateAsync(WebApiActionBase.Value(value), id), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null);
public IActionResult Update([FromBody] CustomerGroup value, string?id, string?company) { return(new WebApiPut <CustomerGroup>(this, () => Factory.Create <ICustomerGroupManager>().UpdateAsync(WebApiActionBase.Value(value), id, company), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null)); }
public IActionResult Update([FromBody] Person value, Guid id) { return(new WebApiPut <Person>(this, () => Factory.Create <IPersonManager>().UpdateAsync(WebApiActionBase.Value(value), id), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null)); }
public IActionResult UpdatePostCodes([FromBody] PostalInfo value, string?country, string?state, string?city) => new WebApiPut <PostalInfo>(this, value, () => _manager.GetPostCodesAsync(country, state, city), () => _manager.UpdatePostCodesAsync(WebApiActionBase.Value(value), country, state, city), operationType: OperationType.Update, statusCode: HttpStatusCode.OK, alternateStatusCode: null);