Пример #1
0
        public async Task <IActionResult> RestoreTemplate([FromBody] TemplateContentUpdateModel model,
                                                          [FromRoute] string templateId, [FromRoute] int version)
        {
            Guard.ArgumentNotNull(model, nameof(model));

            if (model.TemplateId != templateId)
            {
                ModelState.AddModelError("TemplateId", "TemplateId in payload doesn't match route parameter.");
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ValidatedApiResponse <int> result = await _client.RestoreContent(new TemplateContentUpdateCommand
            {
                TemplateId = model.TemplateId,
                TemplateFundingLinesJson = model.TemplateFundingLinesJson,
                Version = version
            });

            switch (result.StatusCode)
            {
            case HttpStatusCode.OK:
                return(Ok(result.Content));

            case HttpStatusCode.BadRequest:
                return(BadRequest(result.ModelState));

            default:
                return(StatusCode((int)result.StatusCode));
            }
        }
Пример #2
0
        public async Task <IActionResult> UpdateTemplateContent([FromBody] TemplateContentUpdateModel model)
        {
            Guard.ArgumentNotNull(model, nameof(model));

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ValidatedApiResponse <int> result = await _client.UpdateTemplateContent(new TemplateContentUpdateCommand
            {
                TemplateId = model.TemplateId,
                TemplateFundingLinesJson = model.TemplateFundingLinesJson
            });

            switch (result.StatusCode)
            {
            case HttpStatusCode.OK:
                return(Ok(result.Content));

            case HttpStatusCode.BadRequest:
                return(BadRequest(result.ModelState));

            default:
                return(StatusCode((int)result.StatusCode, "There was an error processing your request. Please try again."));
            }
        }