public Item Post(ItemBasic item, bool readOnlyAtLibrary) { if (item == null) { throw new ArgumentNullException(nameof(item)); } var user = _folioUserService.ByUserName(AppSettings["foliousername"]); var source = new Source { Id = user.Id, Personal = user.Personal }; item.CirculationNotes.Add(new CirculationNote { NoteType = "Check in", Note = _chillinTextRepository.ByTextField("checkInNote").CheckInNote, Source = source }); if (readOnlyAtLibrary) { item.CirculationNotes.Add(new CirculationNote { NoteType = "Check out", Note = _chillinTextRepository.ByTextField("checkOutNote").CheckOutNote, Source = source }); } var response = _folioRepository.Post(path, _jsonService.SerializeObject(item)); return(_jsonService.DeserializeObject <Item>(response)); }
public async Task <T> DeleteAsync <T>(string resource, object requestBody, Dictionary <string, string> additioalHeaders = null) { using (var client = CreateHttpClient(DefaultHeaders(additioalHeaders))) { var jsonString = _jsonService.SerializeObject(requestBody); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); using (var request = new HttpRequestMessage { Content = content, Method = HttpMethod.Delete, RequestUri = new Uri(GetRequestUrl(BaseUrl, resource)) }) { using (var response = await client.SendAsync(request)) { ThrowIfNotSuccess(response); var data = await response.Content.ReadAsStringAsync(); return(_jsonService.DeserializeObject <T>(data)); } } } }
public Task <T> PutAsync <T>(string resource, object requestBody, Dictionary <string, string> additioalHeaders = null) { var jsonString = _jsonService.SerializeObject(requestBody); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); return(PutAsync <T>(resource, content, CancellationToken.None, additioalHeaders)); }
public Instance Post(InstanceBasic item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } var response = _folioRepository.Post(path, _jsonService.SerializeObject(item)); return(_jsonService.DeserializeObject <Instance>(response)); }
private Task HandleException(Exception exception, HttpContext context) { var payload = _jsonService.SerializeObject <ErrorResponseDto>(new ErrorResponseDto { Error = "we are sorry. An error occured due to an unexpected turn of events. :D " }); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(context.Response.WriteAsync(payload)); }
public async Task <HttpResponse> PostAsync(string url, object content, string token = null) { try { using (var client = new HttpClient()) { if (!string.IsNullOrEmpty(token)) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); } using (var request = new HttpRequestMessage(HttpMethod.Post, url)) { var json = _jsonHanlde.SerializeObject(content); using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json")) { request.Content = stringContent; using (var response = await client .SendAsync(request, HttpCompletionOption.ResponseHeadersRead) .ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); var valueResponse = response.Content.ReadAsStringAsync().Result; return(HttpResponse.Build(response.StatusCode, valueResponse)); } } } } } catch (Exception ex) { return(HttpResponse.Build(HttpStatusCode.InternalServerError, ex)); } }
public static Action <IApplicationBuilder> HandleApiException(ILoggerFactory loggerFactory) { return(appBuilder => { appBuilder.Run(async context => { IJsonService jsonService = (IJsonService)context.RequestServices.GetService(typeof(IJsonService)); var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>(); if (exceptionHandlerFeature != null) { var logger = loggerFactory.CreateLogger("Serilog Global exception logger"); logger.LogError(500, exceptionHandlerFeature.Error, exceptionHandlerFeature.Error.Message); } context.Response.StatusCode = 500; await context.Response.WriteAsync(jsonService.SerializeObject(new ErrorDto() { Message = "Serverda hata oluştu. Teknik destek ekibi ile iletişime geçiniz." })); }); }); }