Exemple #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));
        }
Exemple #2
0
        // GET: Doctors
        public ActionResult AdminIndex(string sortOrder, string currentFilter, string searchString, int?page)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            ViewBag.CurrentSort     = sortOrder;
            ViewBag.SurnameSortParm = String.IsNullOrEmpty(sortOrder) ? "surname_desc" : "";
            ViewBag.NameSortParm    = sortOrder == "Name" ? "name_desc" : "Name";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            var doctors = from p in db.Doctors
                          select p;

            if (!String.IsNullOrEmpty(searchString))
            {
                doctors = from pa in db.Doctors
                          where pa.Name.Contains(searchString) ||
                          pa.Surname.Contains(searchString)
                          select pa;
            }
            else
            {
                doctors = from pa in db.Doctors
                          select pa;
            }

            switch (sortOrder)
            {
            case "surname_desc":
                doctors = doctors.OrderByDescending(s => s.Surname);
                break;

            case "Name":
                doctors = doctors.OrderBy(s => s.Name);
                break;

            case "name_desc":
                doctors = doctors.OrderByDescending(s => s.Name);
                break;

            default:
                doctors = doctors.OrderBy(s => s.Surname);
                break;
            }

            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            return(View(doctors.ToPagedList(pageNumber, pageSize)));
        }
 // GET: Clinics
 public ActionResult AdminIndex()
 {
     using (Verification v = new Verification(Request)) if (!v.IsAdmin())
         {
             return(RedirectToAction("InsufficientPermission", "Account"));
         }
     return(View(db.Clinics.ToList()));
 }
 // GET: Clinics/Create
 public ActionResult Create()
 {
     using (Verification v = new Verification(Request)) if (!v.IsAdmin())
         {
             return(RedirectToAction("InsufficientPermission", "Account"));
         }
     return(View());
 }
Exemple #5
0
 // GET: Doctors/Create
 public ActionResult Create()
 {
     using (Verification v = new Verification(Request)) if (!v.IsAdmin())
         {
             return(RedirectToAction("InsufficientPermission", "Account"));
         }
     ViewBag.ClinicId = new SelectList(db.Clinics, "Id", "Name");
     return(View());
 }
Exemple #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            Doctor doctor = db.Doctors.Find(id);

            db.Doctors.Remove(doctor);
            db.SaveChanges();
            return(RedirectToAction("AdminIndex"));
        }
Exemple #7
0
        public ActionResult Create([Bind(Include = "Id,Name,Surname,ClinicId,StartingHour,EndingHour,Specialization,VisitPrice,LicenseNumber,DoctorAccount_Password")] Doctor doctor)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            doctor.RatingsCount        = 0;
            doctor.AverageRating       = 0;
            doctor.DoctorAccount_Login = doctor.LicenseNumber;

            int countErrors = 0;

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    countErrors++;
                }
            }
            if (countErrors == 1)
            {
                var doctors = (from d in db.Doctors
                               where d.LicenseNumber == doctor.LicenseNumber
                               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.Doctors.Add(doctor);
                db.SaveChanges();
                return(RedirectToAction("AdminIndex"));
            }

            ViewBag.ClinicId = new SelectList(db.Clinics, "Id", "Name", doctor.ClinicId);
            return(View(doctor));
        }
Exemple #8
0
        public ActionResult PatientEdit(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin() && v.GetCurrentUserID() != id)
                {
                    id = v.GetCurrentUserID();
                }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Patient patient = db.Patients.Find(id);

            if (patient == null)
            {
                return(HttpNotFound());
            }
            return(View(patient));
        }
Exemple #9
0
        // GET: Patients/Edit/5
        public ActionResult Edit(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Patient patient = db.Patients.Find(id);

            if (patient == null)
            {
                return(HttpNotFound());
            }
            return(View(patient));
        }
        // GET: Clinics/Details/5
        public ActionResult Details(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Clinic clinic = db.Clinics.Find(id);

            if (clinic == null)
            {
                return(HttpNotFound());
            }
            return(View(clinic));
        }
 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));
 }
Exemple #12
0
        // GET: Doctors/Delete/5
        public ActionResult Delete(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Doctor doctor = db.Doctors.Find(id);

            if (doctor == null)
            {
                return(HttpNotFound());
            }
            return(View(doctor));
        }
Exemple #13
0
        // GET: Doctors/Edit/5
        public ActionResult Edit(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin())
                {
                    return(RedirectToAction("InsufficientPermission", "Account"));
                }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Doctor doctor = db.Doctors.Find(id);

            if (doctor == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ClinicId = new SelectList(db.Clinics, "Id", "Name", doctor.ClinicId);
            return(View(doctor));
        }
Exemple #14
0
        public ActionResult Main(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin() && v.GetCurrentUserID() != id)
                {
                    id = v.GetCurrentUserID();
                }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Patient patient = db.Patients.Find(id);

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

            CheckPatientVisitsForArchived(patient.PatientAccount_Login);
            return(View(patient));
        }
Exemple #15
0
        public ActionResult History(int?id)
        {
            using (Verification v = new Verification(Request)) if (!v.IsAdmin() && v.GetCurrentUserID() != id)
                {
                    id = v.GetCurrentUserID();
                }
            if (id == null || id < 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Patient patient = db.Patients.Find(id);

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

            var archivedVisits = (from visits in db.ArchivedVisits
                                  where visits.PatientId == patient.Id
                                  select visits).ToList();

            ViewBag.patientId = id;
            return(View(archivedVisits));
        }
Exemple #16
0
        public ActionResult Create([Bind(Include = "Id,Name,Surname,PhoneNumber,PESELNumber,PatientAddress_City,PatientAddress_Street,PatientAddress_StreetNumber,PatientAddress_HomeNumber,PatientAddress_PostalCode,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 == 1)
            {
                var patient = new Patient
                {
                    Name                        = model.Name,
                    Surname                     = model.Surname,
                    PESELNumber                 = model.PESELNumber,
                    PhoneNumber                 = model.PhoneNumber,
                    PatientAddress_Country      = model.PatientAddress_Country,
                    PatientAddress_City         = model.PatientAddress_City,
                    PatientAddress_Street       = model.PatientAddress_Street,
                    PatientAddress_PostalCode   = model.PatientAddress_PostalCode,
                    PatientAddress_StreetNumber = model.PatientAddress_StreetNumber,
                    PatientAccount_Login        = model.PESELNumber,
                    PatientAccount_Password     = model.PatientAccount_Password,
                    PatientAddress_HomeNumber   = model.PatientAddress_HomeNumber == null ? String.Empty : model.PatientAddress_HomeNumber
                };

                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));
                    }
                }

                using (SurgeryModel db = new SurgeryModel())
                {
                    db.Patients.Add(patient);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
Exemple #17
0
        public ActionResult PatientEdit([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() && v.GetCurrentUserID() != id) id = v.GetCurrentUserID();
            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();
                using (Verification v = new Verification(Request))
                    if (v.IsAdmin())
                    {
                        return(RedirectToAction("AdminIndex", "Patients"));
                    }
                    else
                    {
                        return(RedirectToAction("Main", "Patients", new { id = patient.Id }));
                    }
            }
            return(View(model));
        }