public ActionResult Update_Status(int id, string status) { try { using (var db = new ddiarydbEntities()) { var appointment = (from s in db.Appointments where s.Id == id select s).FirstOrDefault(); if (appointment.DateStart > DateTime.Now) { appointment.Status = status; appointment.UpdatedDate = DateTime.Now; db.Entry(appointment).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } catch { } return(RedirectToAction("Details")); }
// GET: Patient/Details/5 public ActionResult Details(int id = 0, string status = "") { if (id == 0) { if (Session["UserID"] != null) { id = int.Parse(new EncryptDecrypt().Decrypt(Session["UserID"].ToString())); } else { //id = 31223; return(RedirectToAction("Login")); } } PatientViewModel result = new PatientViewModel(); using (var db = new ddiarydbEntities()) { var patient = db.Patient_Master.Where(x => x.Patient_Id == id).FirstOrDefault(); result = new MappingService().Map <Patient_Master, PatientViewModel>(patient); //result.Patient_photo = new PhotoPathTextService().IsAvailable(result.Patient_photo, result.Patient_name); var appointments = (from x in db.Appointments.AsEnumerable() where x.PatientId == id select x).OrderByDescending(x => x.DateStart).ToList <Appointment>(); if (appointments != null) { result.Appointments = new List <AppointmentViewModel>(); foreach (var item in appointments) { if (item.DateStart < DateTime.Now) { item.Status = "Cancel"; item.UpdatedDate = DateTime.Now; db.Entry(item).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } var temp = new MappingService().Map <Appointment, AppointmentViewModel>(item); var doctor = db.Doctor_Master.Where(x => x.Doctor_id == item.DoctorId).FirstOrDefault(); temp.Doctor = new MappingService().Map <Doctor_Master, DoctorViewModel>(doctor); temp.Doctor.DoctorId_Encrypt = new EncryptDecrypt().Encrypt(doctor.Doctor_id.ToString()); temp.AppointmentId_Encrypt = new EncryptDecrypt().Encrypt(temp.Id.ToString()); result.Appointments.Add(temp); } } } return(View(result)); }
public ReturnObject Insert_Appointment(Appointment appointment) { ReturnObject returnData = new ReturnObject(); try { using (var db = new ddiarydbEntities()) { if (db.Appointments.Any(x => x.DateStart == appointment.DateStart && x.DateEnd == appointment.DateEnd)) { returnData.message = "This time slot booked."; returnData.status_code = Convert.ToInt32(Status.AlreadyExists); returnData.data1 = appointment; return(returnData); } appointment.CreatedDate = DateTime.Now; appointment.UpdatedDate = DateTime.Now; db.Appointments.Add(appointment); db.SaveChanges(); Patient_Master patient = new Patient_Master(); patient = db.Patient_Master.Where(x => x.Patient_contact == appointment.PatientMobile).FirstOrDefault(); if (patient == null) { patient = new Patient_Master(); patient.Reg_Date = DateTime.Now; patient.Patient_name = appointment.PatientName; patient.Patient_contact = appointment.PatientMobile; patient.relation = appointment.Relation; patient.IsActive = false; patient.User_Id = db.Doctor_Master.Where(x => x.Doctor_id == appointment.DoctorId).Select(x => x.User_id).FirstOrDefault(); db.Patient_Master.Add(patient); db.SaveChanges(); } appointment.PatientId = patient.Patient_Id; db.Entry(appointment).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); try { var doctor = db.Doctor_Master.Where(x => x.Doctor_id == appointment.DoctorId).FirstOrDefault(); var sms = "Your Appointment is Booked Successfully! Appointment booked with Dr." + doctor.Doctor_name + " on " + appointment.DateStart.ToString("dd MMM yyyy") + " " + appointment.DateStart.ToString("hh:mm tt") + " to " + appointment.DateEnd.ToString("hh:mm tt"); sms += appointment.Message != "" ? (" Reason: " + appointment.Message) : ""; SmsSend.Send(appointment.PatientMobile, sms); } catch (Exception) { } returnData.message = "Successfull"; returnData.status_code = Convert.ToInt32(Status.Sucess); returnData.data1 = appointment; } } catch (Exception ex) { ErrHandler.WriteError(ex.Message, ex); returnData.data1 = ex; returnData.message = "Oops something went wrong! "; returnData.status_code = Convert.ToInt32(Status.Failed); } return(returnData); }
public ReturnObject Update_Appointment(int id, string status, string msg) { ReturnObject returnData = new ReturnObject(); try { using (var db = new ddiarydbEntities()) { var appointment = (from s in db.Appointments where s.Id == id select s).FirstOrDefault(); if (appointment.DateStart > DateTime.Now) { appointment.Status = status; } else { appointment.Status = "Cancel"; } //appointment.CreatedDate = DateTime.Now; appointment.UpdatedDate = DateTime.Now; db.Entry(appointment).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var sms = ""; var doctor = db.Doctor_Master.Where(x => x.Doctor_id == appointment.DoctorId).FirstOrDefault(); if (appointment.Status == "Accept") { sms = "Your Appointment is Accepted Successfully! Appointment booked with Dr." + doctor.Doctor_name + " on " + appointment.DateStart.ToString("dd MMM yyyy") + " " + appointment.DateStart.ToString("hh:mm tt") + " to " + appointment.DateEnd.ToString("hh:mm tt"); Patient_Master patient = db.Patient_Master.Where(x => x.Patient_Id == appointment.PatientId).FirstOrDefault(); if (patient != null) { patient.IsActive = true; db.Entry(patient).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } DoctorPatient_Master doctorPatient = new DoctorPatient_Master(); doctorPatient = (from x in db.DoctorPatient_Master.AsEnumerable() where x.PatientId == appointment.PatientId && x.DoctorId == appointment.DoctorId select x).FirstOrDefault(); if (doctorPatient == null) { doctorPatient = new DoctorPatient_Master(); doctorPatient.DoctorId = appointment.DoctorId; doctorPatient.PatientId = appointment.PatientId; doctorPatient.IsActive = true; doctorPatient.CreatedDate = DateTime.Now; doctorPatient.UpdatedDate = DateTime.Now; db.DoctorPatient_Master.Add(doctorPatient); db.SaveChanges(); } else { doctorPatient.UpdatedDate = DateTime.Now; db.Entry(doctorPatient).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } else if (appointment.Status == "Cancel") { sms = "Your Appointment booked on " + appointment.DateStart.ToString("dd MMM yyyy") + " " + appointment.DateStart.ToString("hh:mm tt") + " to " + appointment.DateEnd.ToString("hh:mm tt") + " is Canceled by Dr." + doctor.Doctor_name + "."; sms = msg != "" ? (sms + " Reason: " + msg) : sms; } SmsSend.Send(appointment.PatientMobile, sms); returnData.message = "Successfull"; returnData.status_code = Convert.ToInt32(Status.Sucess); returnData.data1 = appointment; } } catch (Exception ex) { ErrHandler.WriteError(ex.Message, ex); returnData.data1 = ex; returnData.message = "Oops something went wrong! "; returnData.status_code = Convert.ToInt32(Status.Failed); } return(returnData); }
public ReturnObject Update_Appointment(Appointment appointment) { ReturnObject returnData = new ReturnObject(); try { if (appointment.Id > 0) { using (var db = new ddiarydbEntities()) { var dbAppointment = db.Appointments.Where(x => x.Id == appointment.Id).FirstOrDefault(); if (db.Appointments.Any(x => x.Id != appointment.Id && x.DateStart == appointment.DateStart && x.DateEnd == appointment.DateEnd)) { returnData.message = "This time slot booked."; returnData.status_code = Convert.ToInt32(Status.AlreadyExists); returnData.data1 = appointment; return(returnData); } dbAppointment.DateStart = appointment.DateStart; dbAppointment.DateEnd = appointment.DateEnd; dbAppointment.DoctorId = appointment.DoctorId; dbAppointment.PatientId = appointment.PatientId; dbAppointment.PatientName = appointment.PatientName; dbAppointment.PatientMobile = appointment.PatientMobile; dbAppointment.Relation = appointment.Relation; dbAppointment.Status = appointment.Status; dbAppointment.SessionId = appointment.DateStart.ToString("ddMMyyyyHHmm") + appointment.DateEnd.ToString("HHmm"); dbAppointment.UpdatedDate = DateTime.Now; //dbAppointment.Message = appointment.Message; db.Entry(dbAppointment).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); try { var doctor = db.Doctor_Master.Where(x => x.Doctor_id == dbAppointment.DoctorId).FirstOrDefault(); var sms = "Your Appointment is Updated Successfully!" + Environment.NewLine + "Now, Appointment booked with Dr." + doctor.Doctor_name + " on " + dbAppointment.DateStart.ToString("dd MMM yyyy") + " " + dbAppointment.DateStart.ToString("hh:mm tt") + " to " + dbAppointment.DateEnd.ToString("hh:mm tt"); sms += appointment.Message != "" ? Environment.NewLine + (" Reason: " + appointment.Message) : ""; SmsSend.Send(appointment.PatientMobile, sms); } catch (Exception) { } returnData.message = "Successfull"; returnData.status_code = Convert.ToInt32(Status.Sucess); returnData.data1 = dbAppointment; } } else { returnData.message = "Oops something went wrong! "; returnData.status_code = Convert.ToInt32(Status.Failed); } } catch (Exception ex) { ErrHandler.WriteError(ex.Message, ex); returnData.data1 = ex; returnData.message = "Oops something went wrong! "; returnData.status_code = Convert.ToInt32(Status.Failed); } return(returnData); }