public ActionResult AddVisit(DoctorFreeTimeViewModel model)
        {
            Patient  patient  = db.PatientSet.Find(model.PatientId);
            WorkTime record   = new WorkTime();
            FreeTime freeTime = db.FreeTimeSet.Find(model.FreeTimeId);
            Doctor   doctor   = db.DoctorSet.Find(model.DoctorId);

            if (patient != null)
            {
                if (ModelState.IsValid && model.DoctorId != -1 && model.FreeTimeId != -1)
                {
                    record.Doctor    = doctor;
                    record.StartTime = freeTime.StartTime;
                    record.Patient   = patient;

                    patient.WorkTime.Add(record);

                    db.FreeTimeSet.Remove(freeTime);

                    db.Entry(patient).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Visits", patient));
                }
            }
            ViewBag.Message = "Выберите врача и время";
            return(RedirectToAction("Visits", patient));
        }
        public ActionResult AddVisit()
        {
            ApplicationUserManager userManager = HttpContext.GetOwinContext()
                                                 .GetUserManager <ApplicationUserManager>();

            var     user    = userManager.FindById(User.Identity.GetUserId());
            Patient patient = db.PatientSet.Find(user.PersonId);

            if (patient == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (patient == null)
            {
                return(HttpNotFound());
            }

            ViewBag.PatientId = patient.Id;
            List <Doctor> docList = db.DoctorSet.Where(d => d.FreeTime.Count != 0).ToList();

            if (docList.Count == 0)
            {
                ViewBag.Message = "Нет свободного времени";
                ViewBag.Visits  = patient.WorkTime;
                return(View("Visits", patient));
            }

            ViewBag.Doctors = new SelectList(docList, "Id", "FIO");

            foreach (Doctor d in docList)
            {
                ViewData[d.FIO] = new SelectList(d.FreeTime, "Id", "StartTime");
            }

            ViewBag.Jobs = new SelectList((from Doctor d in docList select d.Job).Distinct().ToList());
            if (db.FreeTimeSet.Count() == 0)
            {
                ViewBag.Message = "Нет свободного времени";
                return(RedirectToAction("Index"));
            }
            DoctorFreeTimeViewModel model = new DoctorFreeTimeViewModel();

            model.PatientId = (int)patient.Id;

            return(View(model));
        }
Exemple #3
0
        public ActionResult AddVisit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Patient patient = db.PatientSet.Find(id);

            if (patient == null)
            {
                return(HttpNotFound());
            }

            ViewBag.PatientId = id;

            foreach (Doctor d in db.DoctorSet)
            {
                ViewData[d.FIO] = new SelectList(d.FreeTime, "Id", "StartTime");
            }

            List <Doctor> docList = db.DoctorSet.Where(d => d.FreeTime.Count != 0).ToList();

            ViewBag.Doctors = new SelectList(docList, "Id", "FIO");
            ViewBag.Jobs    = new SelectList((from Doctor d in docList select d.Job).Distinct().ToList());

            if (db.FreeTimeSet.Count() == 0)
            {
                ViewBag.Message     = "Нет свободного времени";
                ViewBag.IllnessList = new SelectList(patient.MedCard.Illness, "Id", "Name");
                ViewBag.RecordsList = new SelectList(patient.MedCard.DocRecord, "Id", "Diagnos");

                SelectList list = new SelectList(patient.WorkTime, "Id", "StartTime");
                ViewBag.VisitsList = list;
                foreach (var item in patient.WorkTime)
                {
                    ViewData[item.StartTime.ToString()] = item.Doctor.FIO;
                    ViewData[item.Doctor.FIO]           = item.Doctor.Job;
                }
                return(View("Edit", patient));
            }
            DoctorFreeTimeViewModel model = new DoctorFreeTimeViewModel();

            model.PatientId = (int)id;

            return(View(model));
        }