public async Task <ActionResult> CustomerMove(int key, [SingleParameterBinder(typeof(NewAddress))] NewAddress newAddress) { if (newAddress == null) { return(this.Problem(ProblemJsonBuilder.CreateBadParameters())); } try { var customer = await customerRepository.GetEnitityByKeyAsync(key); var hypermediaCustomer = new HypermediaCustomer(customer); hypermediaCustomer.MoveAction.Execute(newAddress); return(Ok()); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } catch (CanNotExecuteActionException) { return(this.CanNotExecute()); } catch (ActionParameterValidationException e) { var problem = new ProblemJson() { Title = $"Can not use provided object of type '{typeof(NewAddress)}'", Detail = e.Message, ProblemType = "WebApiHypermediaExtensionsCore.Hypermedia.BadActionParameter", StatusCode = 422 // Unprocessable Entity }; return(this.UnprocessableEntity(problem)); } }
public async Task <ActionResult> BuyCar(int key, BuyCarParameters parameter) { if (parameter == null) { var problem = new ProblemJson { Title = $"Can not use provided object of type '{typeof(BuyCarParameters)}'", Detail = "Json or contained links might be invalid", ProblemType = "WebApi.HypermediaExtensions.Hypermedia.BadActionParameter", StatusCode = 422 // Unprocessable Entity }; return(this.UnprocessableEntity(problem)); } try { //shortcut for get car from repository var car = new HypermediaCarHto(parameter.Brand, parameter.CarId); var customer = await customerRepository.GetEnitityByKeyAsync(key).ConfigureAwait(false); //do what has to be done return(Ok()); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } catch (CanNotExecuteActionException) { return(this.CanNotExecute()); } }
public async Task <ActionResult> RemoveCustomer(int key) { try { return(Ok()); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } catch (CanNotExecuteActionException) { return(this.CanNotExecute()); } catch (ActionParameterValidationException e) { var problem = new ProblemJson() { Title = $"Can not use provided object of type '{typeof(NewAddress)}'", Detail = e.Message, ProblemType = "WebApi.HypermediaExtensions.Hypermedia.BadActionParameter", StatusCode = 422 // Unprocessable Entity }; return(this.UnprocessableEntity(problem)); } }
public ActionResult GetEntity(string brand, int key) { try { // short cut for example, we should actually call the Car repo and get a Car domain object var result = new HypermediaCar(brand, key); return(Ok(result)); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } }
public async Task <ActionResult> GetEntity(int key) { try { var customer = await customerRepository.GetEnitityByKeyAsync(key); var result = new HypermediaCustomer(customer); return(Ok(result)); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } }
public async Task <ActionResult> MarkAsFovoriteAction(int key) { try { var customer = await customerRepository.GetEnitityByKeyAsync(key); var hypermediaCustomer = new HypermediaCustomer(customer); hypermediaCustomer.MarkAsFavoriteAction.Execute(); return(Ok()); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } catch (CanNotExecuteActionException) { return(this.CanNotExecute()); } }
public async Task <ActionResult> MarkAsFavoriteAction([HypermediaActionParameterFromBody] MarkAsFavoriteParameters favoriteCustomer) { if (favoriteCustomer == null) { var problem = new ProblemJson { Title = $"Can not use provided object of type '{typeof(MarkAsFavoriteParameters)}'", Detail = "Json or contained links might be invalid", ProblemType = "WebApi.HypermediaExtensions.Hypermedia.BadActionParameter", StatusCode = 422 // Unprocessable Entity }; return(this.UnprocessableEntity(problem)); } try { var customer = await customerRepository.GetEnitityByKeyAsync(favoriteCustomer.CustomerId).ConfigureAwait(false); var hypermediaCustomer = customer.ToHto(); hypermediaCustomer.MarkAsFavorite.Execute(favoriteCustomer); return(Ok()); } catch (EntityNotFoundException) { return(this.Problem(ProblemJsonBuilder.CreateEntityNotFound())); } catch (InvalidLinkException e) { var problem = new ProblemJson() { Title = $"Can not use provided object of type '{typeof(MarkAsFavoriteParameters)}'", Detail = e.Message, ProblemType = "WebApi.HypermediaExtensions.Hypermedia.BadActionParameter", StatusCode = 422 // Unprocessable Entity }; return(this.UnprocessableEntity(problem)); } catch (CanNotExecuteActionException) { return(this.CanNotExecute()); } }