Beispiel #1
0
        public ActionResult AddConsultation()
        {
            var user   = User.Identity.GetUserId();
            var doctor = db.Psychologists.Single(c => c.ApplicationUserId == user);
            var date   = DateTime.Now.Date;

            var appointment = db.Appointments.Include(c => c.Schedule).Include(c => c.Patient).Where(c => c.Schedule.PsychologistId == doctor.Id).Where(c => c.Status == true).Where(c => c.AppointmentDate >= date).Select(c => c.PatientId).ToList();
            var Patients    = db.Patients.ToList();


            var collection = new ConsultationCollection
            {
                Consultation = new Consultation(),

                Appointments = db.Appointments.Where(c => c.Schedule.PsychologistId == doctor.Id).Where(c => c.Status == true).ToList(),

                Patients = db.Patients.Where(c => c.BookedPsychologistId == doctor.Id).Where(c => c.AppointmentStatus == true).ToList(),
            };

            return(View(collection));
        }
Beispiel #2
0
        public ActionResult AddConsultation(ConsultationCollection model)
        {
            string user = User.Identity.GetUserId();

            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (model.ImageUpload == null || model.ImageUpload.ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "This field is required");
            }
            else if (!validImageTypes.Contains(model.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }

            var collection = new ConsultationCollection
            {
                Consultation = model.Consultation,
                Patients     = db.Patients.ToList()
            };

            if (model.Consultation.ConsultationDate != DateTime.Now.Date)
            {
                ViewBag.Messege = $"Consultation date Occurs only Today, change date to: {DateTime.Now.Date} ";
                return(View(collection));
            }

            var consultation = new Consultation();

            if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
            {
                var uploadDir = "~/Content/uploads";
                var imagePath = Path.Combine(Server.MapPath(uploadDir), model.ImageUpload.FileName);
                var imageUrl  = Path.Combine(uploadDir, model.ImageUpload.FileName);
                model.ImageUpload.SaveAs(imagePath);
                consultation.ImageUrl = imageUrl;
            }


            var doctor = db.Psychologists.Single(c => c.ApplicationUserId == user);

            consultation.PatientId        = model.Consultation.PatientId;
            consultation.PsychologistId   = doctor.Id;
            consultation.ConsultationDate = model.Consultation.ConsultationDate;
            consultation.TreatmentPlan    = model.Consultation.TreatmentPlan;
            consultation.Diagnosis        = model.Consultation.Diagnosis;
            var Appointment = db.Appointments.Single(c => c.PatientId == model.Consultation.PatientId);

            Appointment.CompletedStatus = true;
            var patient = db.Patients.Single(c => c.Id == model.Consultation.PatientId);

            patient.CompletedStatus = true;

            patient.AppointmentStatus = false;
            Appointment.Status        = false;



            db.Consultations.Add(consultation);
            db.SaveChanges();


            return(RedirectToAction("ListOfConsultation"));
        }