public async Task <IActionResult> Post([FromBody] WidgetModel widget) { if (widget == null || !ModelState.IsValid) { throw new ApiException("Model error encountered", HttpStatusCode.BadRequest, ModelState); } var result = await service.Create(widget.ToEntity(this.User.GetUserId())); return(Created(Url.Link(RouteConstants.WidgetSelfRoute, new { id = result.Id }), result)); }
public async Task <IActionResult> Update([FromRoute] string id, [FromBody] WidgetModel model) { if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var widget = await service.Find(id); if (widget.User != this.User.GetUserId()) { return(Unauthorized()); } // INFO: I know this is bad, may be the model should have id's anyway. var result = await service.Update(model.ToEntity(id, this.User.GetUserId())); return(Ok(result)); }