public HttpResponseMessage PostNewAccount([FromBody] Patient_Account newAccount) { try { using (Medical_Assistant_System_Entities entities = new Medical_Assistant_System_Entities()){ entities.Patient_Account.Add(newAccount); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, newAccount); message.Headers.Location = new Uri(Request.RequestUri + newAccount.Id_Account.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//test... public HttpResponseMessage PutAccount(int id, Patient_Account newAccount) { try { using (Medical_Assistant_System_Entities entities = new Medical_Assistant_System_Entities()) { var entity = entities.Patient_Account.FirstOrDefault(p => p.Id_Account == id); if (entity != null) { entity.Phone_Number = newAccount.Phone_Number; entity.P_Personal_Infomation.Add((P_Personal_Infomation)newAccount.P_Personal_Infomation); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Account with id =" + id.ToString() + " not found to update")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }