예제 #1
0
 public ActionResult Create(Medic medic)
 {
     if (ModelState.IsValid) {
         medicRepository.InsertOrUpdate(medic);
         medicRepository.Save();
         return RedirectToAction("Index");
     } else {
         ViewBag.PossiblemedicTypes = medictypeRepository.All;
         return View();
     }
 }
예제 #2
0
 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);
 }
예제 #3
0
        // 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);
            }
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        // 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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 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);
 }