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> NewCustomerAction([SingleParameterBinder(typeof(CreateCustomerParameters))] CreateCustomerParameters createCustomerParameters) { if (createCustomerParameters == null) { return(this.Problem(ProblemJsonBuilder.CreateBadParameters())); } var createdCustomer = await customersRoot.CreateCustomerAction.Execute(createCustomerParameters); // Will create a Location header with a URI to the result. return(this.Created(new HypermediaCustomer(createdCustomer))); }
public async Task <ActionResult> NewCustomerAction(CreateCustomerParameters createCustomerParameters) { if (createCustomerParameters == null) { return(this.Problem(ProblemJsonBuilder.CreateBadParameters())); } var createdCustomer = await customersRoot.CreateCustomer.ExecuteAsync(createCustomerParameters).ConfigureAwait(false); // Will create a Location header with a URI to the result. return(this.Created(createdCustomer)); }
public ActionResult NewQueryAction([SingleParameterBinder(typeof(CustomerQuery))] CustomerQuery query) { if (query == null) { return(this.Problem(ProblemJsonBuilder.CreateBadParameters())); } if (!customersRoot.CreateQueryAction.CanExecute()) { return(this.CanNotExecute()); } // Will create a Location header with a URI to the result. return(this.CreatedQuery(typeof(HypermediaCustomerQueryResult), query)); }
public async Task <ActionResult> Query([FromQuery] CustomerQuery query) { if (query == null) { return(this.Problem(ProblemJsonBuilder.CreateBadParameters())); } var queryResult = await customerRepository.QueryAsync(query); var resultReferences = new List <HypermediaObjectReferenceBase>(); foreach (var customer in queryResult.Entities) { resultReferences.Add(new HypermediaObjectReference(new HypermediaCustomer(customer))); } var result = new HypermediaCustomerQueryResult(resultReferences, queryResult.TotalCountOfEnties, query); var navigationQuerys = NavigationQuerysBuilder.Build(query, queryResult); result.AddNavigationQueries(navigationQuerys); return(Ok(result)); }