public Dictionary <String, List <String> > Put([FromBody] PassengerRecord value) { if (!string.IsNullOrEmpty(value.Key) && !string.IsNullOrEmpty(value.LastName)) { if (pl.Add(value)) { return(pl.GetList()); } } var res = new Dictionary <String, List <String> >(); res.Add("Error", new List <string> { "Invalid passenger record" }); return(res); }
public async Task <IActionResult> AddRecord(PassengerRecord record) { if (string.IsNullOrEmpty(record.Key) || string.IsNullOrEmpty(record.LastName)) { return(BadRequest(new { Result = false, Message = "Key & last name must not empty" })); } if (record.Key.Length != 6) { return(BadRequest(new { Result = false, Message = "key length must be 6 letters" })); } var res = await MdApi.AddRecord(record); return(PartialView("_PartialPassengerList", res)); }
public static async Task <Dictionary <string, List <String> > > AddRecord(PassengerRecord record) { using (var client = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(record), Encoding.UTF8, "application/json"); var response = await client.PutAsync(new Uri(SystemConstants.MDApiListAddress), content); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); var dict = JsonConvert.DeserializeObject <Dictionary <string, List <String> > >(result); return(dict); } return(null); } }
public void WebApiPUTGET() { var value = new PassengerRecord { Key = "TESTAB", LastName = "Doe", Gender = "MR", FirstName = "John" }; if (pl.Add(value)) { var res = pl.GetList(); Assert.AreEqual(res.Count, 4); Assert.AreEqual(res["LVGVUP"].Count, 2); Assert.AreEqual(res["TESTAB"].Count, 1); Assert.AreEqual((res["TESTAB"][0]), "JOHN/DOEMR"); } }