public HttpResponseMessage Post(Patient patient) { this.patientRepository.SavePatient(patient); var response = Request.CreateResponse<Patient>(System.Net.HttpStatusCode.Created, patient); return response; }
public PatientRepository() { var ctx = HttpContext.Current; if (ctx != null) { if (ctx.Cache[CacheKey] == null) { var patient = new Patient[] { new Patient { Id = 1, Name = "Glenn Block", Allergy= "None" }, }; ctx.Cache[CacheKey] = patient; } } }
public bool SavePatient(Patient patient) { var ctx = HttpContext.Current; if (ctx != null) { try { var currentData = ((Patient[])ctx.Cache[CacheKey]).ToList(); currentData.Add(patient); ctx.Cache[CacheKey] = currentData.ToArray(); return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } } return false; }