Exemplo n.º 1
0
        protected ActionResult CreateEdit(int doctorId, Patient visit)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (visit.IsEnded)
                    {
                        throw new HttpException(400, "Nie można edytować lub tworzyć zakończonej wizyty");
                    }
                    var uow        = UnitOfWorkPerRequest.Get();
                    var repository = new Repository <Patient>(uow);
                    var docRepo    = new Repository <Doctor>(uow);
                    var doctor     = docRepo.Get(doctorId);
                    if (doctor == null)
                    {
                        throw new HttpException(404, "Podany doktor nie istnieje");
                    }

                    if (visit.Id <= 0)
                    {
                        repository.Add(visit);
                        doctor.PatientsList.Add(visit);
                    }
                    uow.Commit();
                    return(RedirectToAction("Details", "Doctors", new { id = doctorId, visitsDate = visit.VisitTime.Date }));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Niepoprawne dane.");
            }
            return(RedirectToAction("Details", "Doctors", new { id = doctorId }));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var uow     = UnitOfWorkPerRequest.Get();
            var repo    = new Repository <Doctor>(uow);
            var doctors = new List <Doctor>(repo.Query());

            return(View(doctors));
        }
Exemplo n.º 3
0
        private bool removeUser(int doctorId)
        {
            var uow          = UnitOfWorkPerRequest.Get();
            var repo         = new Repository <Doctor>(uow);
            var repoPatients = new Repository <Patient>(uow);

            repoPatients.Delete(repo.Get(doctorId).PatientsList);
            repo.Delete(repo.Get(doctorId));
            uow.Commit();
            return(true);
        }
Exemplo n.º 4
0
        //
        // GET: /Doctors/Edit/5

        public ActionResult Edit(int id)
        {
            Doctor doctor;
            var    uow        = UnitOfWorkPerRequest.Get();
            var    repository = new Repository <Doctor>(uow);

            doctor = repository.Get(id);
            if (doctor != null)
            {
                return(View("Create", doctor));
            }
            throw new HttpException(404, "Brak doktora z podanym id.");
        }
Exemplo n.º 5
0
        public ActionResult Create(FormCollection doctorFormCollection)
        {
            Doctor doctor = null;

            try
            {
                if (ModelState.IsValid)
                {
                    var uow        = UnitOfWorkPerRequest.Get();
                    var repository = new Repository <Doctor>(uow);

                    int id = 0;
                    try
                    {
                        id = Convert.ToInt32(doctorFormCollection.Get("Id"));
                    }
                    catch (FormatException) {}
                    if (id > 0)
                    {
                        doctor = repository.Get(id);
                    }

                    if (doctor == null)
                    {
                        doctor = new Doctor();
                    }
                    doctor.Name    = doctorFormCollection.Get("Name");
                    doctor.Surname = doctorFormCollection.Get("Surname");
                    doctor.Titles  = doctorFormCollection.Get("Titles");
                    var image = getPassedImage();
                    if (image != null)
                    {
                        doctor.Photo = image;
                    }

                    if (id <= 0)
                    {
                        repository.Add(doctor);
                    }
                    uow.Commit();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Niepoprawne dane.");
            }
            return(View(doctor));
        }
Exemplo n.º 6
0
        //
        // GET: /Visits/Edit

        public ActionResult Edit(int doctorId, int visitId)
        {
            Patient visit      = null;
            Doctor  doctor     = null;
            var     uow        = UnitOfWorkPerRequest.Get();
            var     repository = new Repository <Doctor>(uow);

            doctor = repository.Get(doctorId);
            if (doctor != null)
            {
                visit = doctor.PatientsList.FirstOrDefault(x => x.Id == visitId);
            }
            if (visit != null)
            {
                return(CreateEditView(doctorId, visit));
            }
            throw new HttpException(404, "Brak doktora z podanym id.");
        }
Exemplo n.º 7
0
 public ActionResult Finish(int doctorId, int visitId)
 {
     try
     {
         var uow       = UnitOfWorkPerRequest.Get();
         var visitRepo = new Repository <Patient>(uow);
         var visit     = visitRepo.Get(visitId);
         if (visit != null)
         {
             visit.IsEnded = true;
             uow.Commit();
             return(RedirectToAction("Details", "Doctors", new { id = doctorId, visitDate = visit.VisitTime.Date }));
         }
         return(RedirectToAction("Details", "Doctors", new { id = doctorId }));
     }
     catch
     {
         return(RedirectToAction("Details", "Doctors", new { id = doctorId }));
     }
 }
Exemplo n.º 8
0
        //
        // GET: /Doctors/Details/5

        public ActionResult Details(int id = 0, DateTime?visitsDate = null)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }
            var date        = visitsDate ?? DateTime.Now;
            var uow         = UnitOfWorkPerRequest.Get();
            var doctorsRepo = new Repository <Doctor>(uow);
            var doctor      = doctorsRepo.Get(id);

            if (doctor == null)
            {
                throw new HttpException(404, "Brak doktora z podanym id.");
            }
            var patients = new List <Patient>(doctor.PatientsList.Where(x => x.VisitTime.Date == date.Date));

            patients.Sort((x, y) => x.VisitTime.CompareTo(y.VisitTime));
            ViewBag.Doctor = doctor;
            ViewBag.Date   = date;
            return(View(patients));
        }
Exemplo n.º 9
0
 public ActionResult Delete(int doctorId, int visitId)
 {
     try
     {
         var uow       = UnitOfWorkPerRequest.Get();
         var visitRepo = new Repository <Patient>(uow);
         try
         {
             visitRepo.Delete(visitRepo.Get(visitId));
         }
         catch (NullReferenceException)
         {
             // don't give a shit
         }
         uow.Commit();
         return(RedirectToAction("Details", "Doctors", new { id = doctorId }));
     }
     catch
     {
         return(RedirectToAction("Details", "Doctors", new { id = doctorId }));
     }
 }
Exemplo n.º 10
0
        //
        // GET: /UserImageSmall/1
        public FileResult GetImage(int id)
        {
            var uow    = UnitOfWorkPerRequest.Get();
            var doctor = new Repository <Doctor>(uow).Get(id);

            if (doctor == null)
            {
                return(null);
            }
            var imageBytes = doctor.Photo;

            if (imageBytes == null)
            {
                return(null);
            }
            var image = new WebImage(imageBytes);

            if (image.Height > LARGE_IMG_SIZE || image.Width > LARGE_IMG_SIZE)
            {
                image = image.Resize(LARGE_IMG_SIZE, LARGE_IMG_SIZE);
            }
            image = image.Resize(200, 200, true);
            return(File(image.GetBytes(), "image/" + image.ImageFormat));
        }
Exemplo n.º 11
0
 protected void Application_EndRequest(object sender, EventArgs args)
 {
     UnitOfWorkPerRequest.Dispose();
 }
Exemplo n.º 12
0
        // GET api/doctors
        public List <Doctor> Get()
        {
            /*var patients_1 = new List<Patient>
             * {
             *  new Patient
             *  {
             *      Id = 1,
             *      Name = "Anna Zawodna 1",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromSeconds(10)
             *  },
             *
             *  new Patient
             *  {
             *      Id = 2,
             *      Name = "Anna Zdrowa 1",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromSeconds(40)
             *  },
             *
             *  new Patient
             *  {
             *      Id = 3,
             *      Name = "Henryka Prostonos 1",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromMinutes(30)
             *  }
             * };
             * var patients_2 = new List<Patient>
             * {
             *  new Patient
             *  {
             *      Id = 4,
             *      Name = "Anna Zawodna 2",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromSeconds(10)
             *  },
             *
             *  new Patient
             *  {
             *      Id = 5,
             *      Name = "Anna Zdrowa 2",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromMinutes(20)
             *  },
             *
             *  new Patient
             *  {
             *      Id = 6,
             *      Name = "Henryka Prostonos 2",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromMinutes(30)
             *  }
             * };
             * var patients_3 = new List<Patient>
             * {
             *  new Patient
             *  {
             *      Id = 7,
             *      Name = "Anna Zawodna 3",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromSeconds(10)
             *  },
             *
             *  new Patient
             *  {
             *      Id = 8,
             *      Name = "Anna Zdrowa 3",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromMinutes(20)
             *  },
             *
             *  new Patient
             *  {
             *      Id = 9,
             *      Name = "Henryka Prostonos 3",
             *      Duration = TimeSpan.FromSeconds(10),
             *      VisitTime = DateTime.Now + TimeSpan.FromMinutes(30)
             *  }
             * };
             * var docs = new List<Doctor>
             * {
             *  new Doctor
             *  {
             *      Id = 1,
             *      Name = "Andrzej",
             *      PatientsList = patients_1,
             *      Surname = "Góralczyk",
             *      Titles = "dr hab."
             *  },
             *  //new Doctor
             *  //{
             *  //    Id = 2,
             *  //    Name = "Paweł",
             *  //    PatientsList = patients_2,
             *  //    Surname = "Niskowłos",
             *  //    Titles = "prof. dr hab."
             *  //},
             *  //new Doctor
             *  //{
             *  //    Id = 3,
             *  //    Name = "Hieronim",
             *  //    PatientsList = patients_3,
             *  //    Surname = "Anonim",
             *  //    Titles = "prof. zw. dr hab"
             *  //}
             * };
             *
             * return docs;*/

            var uow  = UnitOfWorkPerRequest.Get();
            var repo = new Repository <Doctor>(uow);

            return(new List <Doctor>(repo.Query()));
        }