public ActionResult Create(Medic medic) { if (ModelState.IsValid) { medicRepository.InsertOrUpdate(medic); medicRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossiblemedicTypes = medictypeRepository.All; return View(); } }
public void InsertOrUpdate(Medic medic) { if (medic.medicID == default(int)) { // New entity context.Medics.Add(medic); } else { // Existing entity context.Entry(medic).State = EntityState.Modified; } SignalR.MessageHub.SendMedicUpdate(medic); }
// POST api/Default2 public HttpResponseMessage PostMedic(Medic medic) { if (ModelState.IsValid) { db.Medics.Add(medic); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, medic); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = medic.medicID })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public HttpResponseMessage Post(Medic medic) { if (ModelState.IsValid) { this.medicRepository.InsertOrUpdate(medic); this.medicRepository.Save(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, medic); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = medic.medicID })); return response; } else { var validationResults = this.ModelState.SelectMany(m => m.Value.Errors.Select(x => x.ErrorMessage + "(Property: " + m.Key + ")" )); throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.BadRequest, validationResults)); } }
// PUT api/Default2/5 public HttpResponseMessage PutMedic(int id, Medic medic) { if (ModelState.IsValid && id == medic.medicID) { db.Entry(medic).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public HttpResponseMessage Put(int id, Medic medic) { if (ModelState.IsValid && id == medic.medicID) { this.medicRepository.InsertOrUpdate(medic); this.medicRepository.Save(); return Request.CreateResponse(HttpStatusCode.OK, medic); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public static void SendMedicUpdate(Medic medic) { var context = GlobalHost.ConnectionManager.GetHubContext<MessageHub>(); System.Diagnostics.Trace.WriteLine("Sending medic update"); context.Clients.Group(medic.medicID.ToString()).updateMedic(medic); }