public async Task <IActionResult> DeleteAsync([FromRoute] string userId, [FromRoute] string id, [FromServices] ITargetApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } try { if (!await service.DeleteAsync(userId, 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> GetTargetByIdAsync([FromRoute] string userId, [FromRoute] string id, [FromServices] ITargetApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } var registeredTarget = await service.GetByIdAsync(userId, id); if (registeredTarget == null) { return(NotFound()); } return(Ok(registeredTarget)); }
public async Task <IActionResult> MarkAsCurrentAsync([FromRoute] string userId, [FromRoute] string id, [FromServices] ITargetApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } if (await service.MarkAsCurrent(userId, id) == false) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> AddAsync([FromRoute] string userId, [FromBody] TargetDto target, [FromServices] ITargetApplicationService service) { if (!string.Equals(User.Identity.Name, userId)) { return(Forbid()); } try { var registeredTarget = await service.AddAsync(userId, target); return(CreatedAtRoute(nameof(GetTargetByIdAsync), new { userId, id = registeredTarget.Id }, registeredTarget)); } 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!")); } }