public async Task <IActionResult> GetSerieByIdAsync([FromRoute] string userId, [FromRoute] string targetId, [FromRoute] string id, [FromServices] ISerieApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } var registeredSerie = await service.GetByIdAsync(userId, targetId, id); if (registeredSerie == null) { return(NotFound()); } return(Ok(registeredSerie)); }
public async Task <IActionResult> DeleteAsync([FromRoute] string userId, [FromRoute] string targetId, [FromRoute] string id, [FromServices] ISerieApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } try { if (!await service.DeleteAsync(userId, targetId, id)) { return(NotFound()); } return(StatusCode(204)); } catch (ArgumentException ex) { return(BadRequest(new { reason = ex.Message })); } catch (Exception ex) { Console.WriteLine(ex); return(Problem("Something is not right, calm down calm down! We're working to fix...(I hope so!")); } }
public async Task <IActionResult> AddSerieAsync([FromRoute] string userId, [FromRoute] string targetId, [FromBody] SerieDto serie, [FromServices] ISerieApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } try { var registeredSerie = await service.AddAsync(userId, targetId, serie); return(CreatedAtRoute(nameof(GetSerieByIdAsync), new { userId, targetId, id = registeredSerie.Id }, registeredSerie)); } catch (Application.Exceptions.ApplicationException ex) { return(BadRequest(ex.ToResult())); } catch (ArgumentException ex) { return(BadRequest(new { reason = ex.Message })); } catch (Exception ex) { Console.WriteLine(ex); return(Problem("Something is not right, calm down calm down! We're working to fix...(I hope so!")); } }