Ejemplo n.º 1
0
        public async Task <ActionResult> Query([FromQuery] BlueprintQueryParameters queryParameters)
        {
            if (queryParameters == null)
            {
                return(this.Problem(ProblemFactory.BadParameters()));
            }

            var blueprintQuery = new BlueprintsQuery
            {
                MaxProductionEfford = queryParameters.MaxProductionEfford,
                NameContains        = queryParameters.ModelName
            };

            var result = await CommandHandler.Query(blueprintQuery);

            return(result.Match(
                       success =>
            {
                var resultHto = Ok(new BlueprintQueryResultHto(success.Result, queryParameters));
                return resultHto;
            },
                       notReachable => this.Problem(ProblemFactory.ServiceUnavailable()),
                       invalidQuery => this.Problem(ProblemFactory.BadParameters()),
                       error => this.Problem(ProblemFactory.Exception(error.Exception))
                       ));
        }
Ejemplo n.º 2
0
        public ActionResult NewQuery(BlueprintQueryParameters queryParameters)
        {
            if (queryParameters == null)
            {
                return(this.Problem(ProblemFactory.BadParameters()));
            }

            var canQueryResult = CommandHandler.CanQueryBlueprints();

            return(canQueryResult.Match(
                       // Will create a Location header with a URI to the result.
                       available => this.CreatedQuery(typeof(BlueprintQueryResultHto), queryParameters),
                       notAvailable => this.Problem(ProblemFactory.OperationNotAvailable()),
                       notReachable => this.Problem(ProblemFactory.ServiceUnavailable()),
                       error => this.Problem(ProblemFactory.Exception(error.Exception))
                       ));
        }
        public BlueprintQueryResultHto(ICollection <Domain.Design.RobotBlueprint> entities, BlueprintQueryParameters queryParameters) : base(queryParameters)
        {
            Count = entities.Count;

            var relatedBlueprints = entities.Select(b => new RelatedEntity(DefaultHypermediaRelations.EmbeddedEntities.Item, new HypermediaObjectReference(new RobotBlueprintHto(b))));

            Entities.AddRange(relatedBlueprints);
        }