public async Task <IActionResult> AddApplicationAsync( [FromRoute] string organisationId, [FromRoute] string teamId, [FromBody] DataContracts.Application app, [FromServices] IApplicationService service, [FromServices] IUserService userService) { if (string.IsNullOrWhiteSpace(organisationId) || string.IsNullOrWhiteSpace(teamId) || string.IsNullOrWhiteSpace(app?.Name)) { return(BadRequest(new { reason = $"Invalid parameters" })); } try { var hasPermission = await userService.IsOwner(organisationId, teamId, User.Identity.Name); if (!hasPermission) { return(Forbid()); } app.CreatedAt = DateTime.Now; app.Id = null; var appResult = await service.AddAsync(organisationId, teamId, app); return(CreatedAtRoute(nameof(GetApplicationAsync), new { organisationId, teamId, appId = app.Name }, appResult)); } catch (NameAlreadyUsedException ex) { return(BadRequest(new { reason = ex.Message })); } catch (Exception) { return(StatusCode(statusCode: (int)HttpStatusCode.InternalServerError)); } }
public async Task <ActionResult <Application> > Add([Bind("ApplicantId", "JobId")] Application application) => await _applicationService.AddAsync(application);