public IActionResult Add(Search search) { // Create the Customer and show the Edit page with default values var request = WebRequest.Create(_serviceSetting.URI + "customer/"); request.Method = "POST"; request.ContentType = "text/json"; using (var stream = request.GetRequestStream()) { var customer = new Customer { Name = search.Query, Gender = "", HouseNumber = 1, AddressLine1 = "", State = "", Country = "", Category = "", DateOfBirth = new DateTime() }; using (StreamWriter sw = new StreamWriter(stream)) sw.Write(JsonConvert.SerializeObject(customer)); } using (var response = request.GetResponse()) { var loc = response.Headers["Location"]; return RedirectToAction("Edit", new { id = loc.Substring(loc.LastIndexOf('/') + 1) }); } }
public IActionResult Search(Search search) { search.ServiceURI = _serviceSetting.URI; if (!string.IsNullOrEmpty(search.Query)) { var request = WebRequest.Create(_serviceSetting.URI + "customer/" + search.Query); using (var response = request.GetResponse()) using (var reader = new StreamReader(response.GetResponseStream())) { search.Result = JsonConvert.DeserializeObject<List<KeyValuePair<int, string>>>(reader.ReadToEnd()); } } return View(search); }