public ReminderItem Get(Guid id) { HttpResponseMessage response = CallWebApi(HttpMethod.Get, id.ToString()); if (response.StatusCode == HttpStatusCode.NotFound) { return(null); } if (response.StatusCode != HttpStatusCode.OK) { throw CreateException(response); } // Read response Body var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); // Parse response Model ReminderItemGetModel model = JsonConvert.DeserializeObject <ReminderItemGetModel>(content); if (model == null) { throw new Exception("Body cannot be parsed as List<ReminderItemGetModel>"); } //Return the Result return(model.ToReminderItem()); }
public IActionResult Get(Guid id) { ReminderItem reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } var model = new ReminderItemGetModel(reminderItem); return(Ok(model)); }
public IActionResult Get(Guid id) { _logger.LogInformation($"{nameof(Get)} called"); var reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } var model = new ReminderItemGetModel(reminderItem); return(Ok(model)); }
public ReminderItem Get(Guid id) { HttpResponseMessage response = CallWebApi( HttpMethod.Get, id.ToString()); //// prepare URL //string relativeUrl = id.ToString(); ////prepare request //var request = new HttpRequestMessage( // HttpMethod.Get, _baseWebApiUrl + relativeUrl); ////add headers //request.Headers.Accept.Add( // new MediaTypeWithQualityHeaderValue("*/*")); ////prepare model ////prepare Request BODY ////send Request and get REsponse //HttpResponseMessage response = _httpClient.SendAsync(request).GetAwaiter().GetResult(); // check rESPONSE STATUS CODES if (response.StatusCode == HttpStatusCode.NotFound) { return(null); } if (response.StatusCode != HttpStatusCode.OK) { throw CreateException(response); } //read response body var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); //parse response model ReminderItemGetModel model = JsonConvert.DeserializeObject <ReminderItemGetModel>(content); if (model == null) { throw new Exception("Bodu cannot be parsed as ReminderItemGetModel. "); } //return the result return(model.ToReminderItem()); }
public IActionResult CreateReminder([FromBody] ReminderItemGetModel reminder) { if (reminder == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var reminderItem = reminder.ToReminderItem(); _reminderStorage.Add(reminderItem); return(CreatedAtRoute( "GetReminder", new { id = reminderItem.Id }, new ReminderItemGetModel(reminderItem))); }
public ReminderItem Get(Guid id) { HttpResponseMessage httpResponseMessage = GetResponseAfterSending( HttpMethod.Get, _baseWebApiUrl + $"/{id}"); if (httpResponseMessage.StatusCode != System.Net.HttpStatusCode.OK) { ThrowException(httpResponseMessage); } string responceContent = httpResponseMessage.Content.ReadAsStringAsync().GetAwaiter().GetResult(); ReminderItemGetModel reminderItemGetModel = JsonConvert.DeserializeObject <ReminderItemGetModel>(responceContent); return(reminderItemGetModel.ToReminderItem()); }
public Guid Add(ReminderItemRestricted reminderItemRestricted) { HttpResponseMessage httpResponseMessage = GetResponseAfterSending( HttpMethod.Post, _baseWebApiUrl, JsonConvert.SerializeObject(new ReminderItemAddModel(reminderItemRestricted))); if (httpResponseMessage.StatusCode != System.Net.HttpStatusCode.Created) { ThrowException(httpResponseMessage); } string responceContent = httpResponseMessage.Content.ReadAsStringAsync().GetAwaiter().GetResult(); ReminderItemGetModel reminderItemGetModel = JsonConvert.DeserializeObject <ReminderItemGetModel>(responceContent); return(reminderItemGetModel.Id); }