protected HttpException Handle(BusinessLogicException businessLogicException) { if (businessLogicException is NotFoundException) { return(ResponseHelper.Get404NotFound(businessLogicException.Message)); } if (businessLogicException is ConflictException) { return(ResponseHelper.Get409Conflict(businessLogicException.Message)); } return(ResponseHelper.Get500InternalServerError("Unknown business logic exception")); }
public Response PostAddUser() { const string invalidRequestBodyError = "Invalid request body"; // Check the body is not empty. //TODO Klopt deze check en/of is deze verstandig op deze manier? if (Request?.MessageBody == null || Request.MessageBody.Length == 0) { throw ResponseHelper.Get400BadRequest(invalidRequestBodyError); } // Try to deserialize the body to an AddUserResource. AddUserResource addUserResource; try { addUserResource = Request.MessageBody.DeserializeJson <AddUserResource>(); } catch (Exception) { throw ResponseHelper.Get400BadRequest(invalidRequestBodyError); } var userService = ServiceFactory.CreateUserService(); User user; try { user = userService.CreateUser(addUserResource.Firstname, addUserResource.Lastname, addUserResource.Username, addUserResource.Email, addUserResource.Password); } catch (ConflictException conflictException) { throw ResponseHelper.Get409Conflict(conflictException.Message); } catch (ValidationException validationException) { throw ResponseHelper.Get400BadRequest(validationException.Message); } var response = new Response(HttpStatusCode.Created); response.Headers.Add("Location", UriHelper.GetUserUri(user.Id)); return(response); }
public Response PostEndSeasonItem(string gameId, string seasonId) { var game = GetGameInfo(gameId); RequestHelper.ValidateId(seasonId); var seasonService = ServiceFactory.CreateSeasonService(game); var season = seasonService.Get(seasonId); if (season == null) { throw ResponseHelper.Get404NotFound($"Season '{seasonId}' does not exist"); } var currentSeason = seasonService.GetCurrentSeason(); if (!currentSeason.Equals(season)) { throw ResponseHelper.Get409Conflict("This is not the current season"); } bool seasonEnded = seasonService.DetermineSeasonEnded(season.Id); if (!seasonEnded) { throw ResponseHelper.Get400BadRequest("The season is not finished yet"); } seasonService.EndSeasonAndCreateNext(seasonId); var seasonUri = UriHelper.GetSeasonUri(gameId, seasonId); var response = new Response(HttpStatusCode.Created); response.Headers.Add("Location", seasonUri); return(response); }