public async Task <string> MakeAnAppointment(Appointment busyTime, DateTime selectedDate, TimeSpan receptionTime, List <string> symptoms) { busyTime.PredictedDiagnoses = PredicateDiagnoses(symptoms); busyTime.IdSymptoms = Symptom.GetSymptomsString(symptoms); busyTime.EndTime = busyTime.StartTime + receptionTime; busyTime.Day = new DateTime(DateTime.Now.Year, selectedDate.Month, selectedDate.Day); List <Appointment> checkTime = db.Appointments.Where(bt => bt.IdDoctor == busyTime.IdDoctor && bt.StartTime == busyTime.StartTime && bt.Day == busyTime.Day).ToList(); if (checkTime.Count > 0) { return("<h3>Время приёма уже занято! Выберите другое время!</h3>"); } List <Appointment> apps = db.Appointments.Where(app => app.IdPatient == busyTime.IdPatient && app.Day == busyTime.Day && !((app.StartTime < busyTime.StartTime && app.EndTime <= busyTime.StartTime) || (app.StartTime >= busyTime.EndTime && app.EndTime > busyTime.EndTime))).ToList <Appointment>(); if (apps.Count != 0) { return("<h3>Извините, но на это время вы записаны к другому врачу!</h3>"); } db.Appointments.Add(busyTime); await db.SaveChangesAsync(); User patient = await db.Patients.FindAsync(busyTime.IdPatient); User doctor = await db.Doctors.FindAsync(busyTime.IdDoctor); MailSender sender = new MailSender(patient.Email); sender.SendMessageForMakeAppointment(doctor, selectedDate, busyTime.StartTime, MailSender.UserType.Patient, Url.Action("Doctor", "Home", new { id = busyTime.IdDoctor }, Request.Url.Scheme)); sender.Recipient = doctor.Email; sender.SendMessageForMakeAppointment(patient, selectedDate, busyTime.StartTime, MailSender.UserType.Doctor); return($"<h3>Запись была осуществлена успешно!</h3><br/><a href={Url.Action("Index","Cabinet")}>В личный кабинет</a>"); }
public async Task <RedirectResult> AddReport(int IdAppointment, [Bind(Exclude = "Date")] DoctorReport report, List <string> symptoms, List <string> complaints, List <string> complaints2, List <string> analyses) { report.Complaints = Symptom.GetSymptomsString(complaints); report.Complaints2 = Symptom.GetSymptomsString(complaints2); report.Analyses = Symptom.GetSymptomsString(analyses); report.IdSymptoms = Symptom.GetSymptomsString(symptoms); report.Date = DateTime.Now; using (var transaction = db.Database.BeginTransaction()) { try { Appointment appointment = await db.Appointments.FindAsync(IdAppointment); db.Appointments.Remove(appointment); db.DoctorReports.Add(report); await db.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } } return(Redirect("/Cabinet")); }