示例#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);
 }