Пример #1
0
        public ActionResult Edit([Bind(Include = "Id,Name,Surname,ClinicId,StartingHour,EndingHour,AverageRating,RatingsCount,Specialization,VisitPrice,LicenseNumber,DoctorAccount_Login,DoctorAccount_Password")] Doctor doctor)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            if (ModelState.IsValid)
            {
                var doctors = (from d in db.Doctors
                               where d.LicenseNumber == doctor.LicenseNumber && d.Id != doctor.Id
                               select d).ToList();

                if (doctor.StartingHour > doctor.EndingHour)
                {
                    ModelState.AddModelError("TimeError", "Godzina rozpoczęcia przyjęć musi być wcześniejsza od godziny zakończenia");
                    ViewBag.ClinicId = new SelectList(db.Clinics, "Id", "Name", doctor.ClinicId);
                    return(View(doctor));
                }

                if (doctors.Count == 1)
                {
                    ModelState.AddModelError("Error", "Lekarz o takim numerze licencji już istnieje");
                    ViewBag.ClinicId = new SelectList(db.Clinics, "Id", "Name", doctor.ClinicId);
                    return(View(doctor));
                }

                db.Entry(doctor).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("AdminIndex"));
            }
            ViewBag.ClinicId = new SelectList(db.Clinics, "Id", "Name", doctor.ClinicId);
            return(View(doctor));
        }
Пример #2
0
        public List <VisitTime> ListVisitsByLicenceNumber(string licenceNumber)
        {
            List <VisitTime> visits;

            using (SurgeryModel sc = new SurgeryModel())
            {
                visits = (from visit in sc.VisitTimes
                          where visit.Doctor.LicenseNumber == licenceNumber
                          orderby visit.Date
                          select visit).ToList();

                foreach (VisitTime vt in visits)
                {
                    sc.Entry(vt).Reference(x => x.Doctor).Load();
                    sc.Entry(vt.Doctor).Reference(x => x.Clinic).Load();
                    sc.Entry(vt).Reference(x => x.Patient).Load();
                }
            }

            return(visits);
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "Id,Date,DoctorId,PatientId")] VisitTime visitTime)
 {
     if (ModelState.IsValid)
     {
         db.Entry(visitTime).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DoctorId  = new SelectList(db.Doctors, "Id", "Name", visitTime.DoctorId);
     ViewBag.PatientId = new SelectList(db.Patients, "Id", "Name", visitTime.PatientId);
     return(View(visitTime));
 }
Пример #4
0
 public ActionResult Edit([Bind(Include = "Id,Name,ClinicAddress_Country,ClinicAddress_City,ClinicAddress_Street,ClinicAddress_StreetNumber,ClinicAddress_HomeNumber,ClinicAddress_PostalCode")] Clinic clinic)
 {
     using (Verification v = new Verification(Request)) if (!v.IsAdmin())
         {
             return(RedirectToAction("InsufficientPermission", "Account"));
         }
     if (clinic.ClinicAddress_HomeNumber == null)
     {
         clinic.ClinicAddress_HomeNumber = string.Empty;
     }
     if (ModelState.IsValid)
     {
         db.Entry(clinic).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("AdminIndex"));
     }
     return(View(clinic));
 }
Пример #5
0
        public ActionResult Edit([Bind(Include = "Id,Date,DoctorId,PatientId,Rating")] ArchivedVisit archivedVisit)
        {
            var visit = (from av in db.ArchivedVisits
                         where av.Id == archivedVisit.Id
                         select av).FirstOrDefault();

            int?oldrating = visit.Rating;

            visit.Rating = archivedVisit.Rating.Value;

            int countErrors = 0;

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    countErrors++;
                }
            }

            if (countErrors == 2)
            {
                db.Entry(visit).State         = EntityState.Modified;
                db.Entry(visit.Patient).State = EntityState.Unchanged;
                db.Entry(visit.Doctor).State  = EntityState.Unchanged;

                db.SaveChanges();

                db.Entry(visit.Patient).State = EntityState.Unchanged;
                db.Entry(visit).State         = EntityState.Unchanged;

                SetRating(visit.DoctorId, visit.Doctor.RatingsCount, oldrating, archivedVisit.Rating.Value);

                return(RedirectToAction("Main", "Patients", new { id = visit.PatientId }));
            }

            ViewBag.DoctorId  = new SelectList(db.Doctors, "Id", "Name", archivedVisit.DoctorId);
            ViewBag.PatientId = new SelectList(db.Patients, "Id", "Name", archivedVisit.PatientId);
            return(View(archivedVisit));
        }
Пример #6
0
        public ActionResult Edit([Bind(Include = "Id,Name,Surname,PhoneNumber,PESELNumber,PatientAddress_Country,PatientAddress_City,PatientAddress_Street,PatientAddress_StreetNumber,PatientAddress_HomeNumber,PatientAddress_PostalCode,PatientAccount_Login,PatientAccount_Password")] Patient model)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            ModelState.SetModelValue("PatientAccount_Login", new ValueProviderResult(model.PESELNumber, null, CultureInfo.InvariantCulture));
            model.PatientAccount_Login = model.PESELNumber;

            ModelState.SetModelValue("PatientAddress_Country", new ValueProviderResult("Polska", null, CultureInfo.InvariantCulture));
            model.PatientAddress_Country = "Polska";

            int countErrors = 0;

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    countErrors++;
                }
            }

            if (countErrors <= 2)
            {
                var patient = (from p in db.Patients
                               where p.Id == model.Id
                               select p).FirstOrDefault();

                var oldPESEL = patient.PESELNumber;

                patient.Name                        = model.Name;
                patient.Surname                     = model.Surname;
                patient.PESELNumber                 = model.PESELNumber;
                patient.PhoneNumber                 = model.PhoneNumber;
                patient.PatientAddress_Country      = model.PatientAddress_Country;
                patient.PatientAddress_City         = model.PatientAddress_City;
                patient.PatientAddress_Street       = model.PatientAddress_Street;
                patient.PatientAddress_PostalCode   = model.PatientAddress_PostalCode;
                patient.PatientAddress_StreetNumber = model.PatientAddress_StreetNumber;
                patient.PatientAccount_Login        = model.PESELNumber;
                patient.PatientAccount_Password     = model.PatientAccount_Password;
                patient.PatientAddress_HomeNumber   = model.PatientAddress_HomeNumber == null ? String.Empty : model.PatientAddress_HomeNumber;

                if (oldPESEL != model.PESELNumber)
                {
                    using (SurgeryModel db = new SurgeryModel())
                    {
                        var patients = (from p in db.Patients
                                        where p.PatientAccount_Login == model.PESELNumber
                                        select p).ToList();

                        if (patients.Count == 1)
                        {
                            ModelState.AddModelError("Error", "Pacjent o takim numerze PESEL już istnieje");
                            return(View(model));
                        }
                    }
                }

                db.Entry(patient).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("AdminIndex", "Patients"));
            }
            return(View(model));
        }