public async Task <ApiResponse <AddFigureResponseData> > AddFigure(
            [FromBody] AddFigureRequest request)
        {
            Result <AddFigureResponseData> response = await _mediator.Send(request);

            return(new ApiResponse <AddFigureResponseData>(response));
        }
        public async Task <IActionResult> PostFigure([FromBody] PostFigureModel model)
        {
            var request = new AddFigureRequest(model.FigureType, model.FigureProps);

            Figure figure = await _mediator.Send(request);

            return(CreatedAtAction(nameof(GetFigure), new { id = figure.Id }, figure));
        }
Example #3
0
        private static AddFigureRequest MakeRequest(string type, IFigureDescription typedDescription)
        {
            var request = new AddFigureRequest
            {
                FigureDescription = typedDescription,
                FigureType        = type
            };

            return(request);
        }
Example #4
0
        public async Task BindModelAsync(ModelBindingContext bindingContext)
        {
            JObject jObject = await ParseJson(bindingContext.HttpContext);

            if (jObject == null || !jObject.ContainsKey("type"))//it should be processed in handler
            {
                bindingContext.Result = ModelBindingResult.Success(MakeRequest(null, null));
                return;
            }

            string type = jObject["type"].Value <string>();

            if (String.IsNullOrWhiteSpace(type))//it should be processed in handler
            {
                bindingContext.Result = ModelBindingResult.Success(MakeRequest(null, null));
                return;
            }

            Result <Type> descriptionTypeResult = _descriptionProvider.GetDescriptionType(type);

            if (descriptionTypeResult.Fail)//it should be processed in handler
            {
                bindingContext.Result = ModelBindingResult.Success(MakeRequest(type, null));
                return;
            }

            Type descriptionType = descriptionTypeResult.Data;

            if (!jObject.ContainsKey("description"))//it should be processed in handler
            {
                bindingContext.Result = ModelBindingResult.Success(MakeRequest(null, null));
                return;
            }

            string description = jObject["description"].ToString();

            IFigureDescription typedDescription = JsonConvert.DeserializeObject(description, descriptionType)
                                                  as IFigureDescription;

            AddFigureRequest request = MakeRequest(type, typedDescription);

            bindingContext.Result = ModelBindingResult.Success(request);
        }