public async Task <IHttpActionResult> CallRequestRegistration([FromUri] string param1, [FromUri] string param2, [FromBody] string param3) { try { var fileText = await Request.Content.ReadAsStringAsync(); if (!CheckingHelper <string> .CheckForNullEmptyWhiteSpace(fileText)) { return(ResponseMessage(RequiredParameterIsLost("Текст файла"))); } FileController.FileController.SaveFile(param1, fileText, Settings.Instance.BasePath); var dbRequest = new DbRequest(); dbRequest.InsertNewFileInfo(param2, param1); var response = new BaseStringResponse() { Error = false, Message = "Запрос выполнен успешно", Response = null }; var resultJson = Serializer.Serialize(response); var result = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new StringContent(resultJson, Encoding.UTF8, "application/json") }; return(ResponseMessage(result)); } catch (Exception exc) { return(ResponseMessage(RequestError(exc.Message))); } }
private HttpResponseMessage RequiredParameterIsLost(string parameterName) { var response = new BaseStringResponse() { Error = true, Message = $"Отсутствует обязательный параметр {parameterName}", Response = null }; var resultJson = Serializer.Serialize(response); return(new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new StringContent(resultJson, Encoding.UTF8, "application/json") }); }
private HttpResponseMessage RequestError(string message) { var response = new BaseStringResponse() { Error = true, Message = message, Response = null }; var resultJson = Serializer.Serialize(response); return(new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new StringContent(resultJson, Encoding.UTF8, "application/json") }); }