public Object StudentCancelScheduledAppointment(int id, string cancelCode, string cancellationReason) { var appointment = _context.Appointments.FirstOrDefault(a => a.ID == id); if (appointment == null) { return(new { success = false, message = "Could not find appointment" }); } if (appointment.CancelCode != cancelCode) { return(new { success = false, message = "Invalid cancel code" }); } AppointmentCancellation appointmentCancellation = new AppointmentCancellation { FirstName = appointment.FirstName, LastName = appointment.LastName, Email = appointment.Email, DateTime = appointment.DateTime, ProfessorID = appointment.ProfessorID, Status = appointment.Status, Reason = cancellationReason, Created = DateTime.Now }; appointment.FirstName = null; appointment.LastName = null; appointment.Email = null; appointment.BannerID = null; appointment.ModifiedAt = DateTime.Now; appointment.Status = Appointment.StatusType.Open; _context.Appointments.Update(appointment); _context.AppointmentCancellations.Add(appointmentCancellation); _context.SaveChanges(); return(new { success = true, message = "Appointment Cancelled" }); }
private void DeleteAppointments(ScheduledHour entity) { DateTime startTime = DateTime.Now; DateTime currentDate = entity.StartDate; DateTime endDate = entity.EndDate; var appointmentLength = new TimeSpan(0, 15, 0); endDate = endDate.AddDays(1); while (currentDate != endDate) { if (CheckDayOfWeek(entity, currentDate)) { var currentTime = entity.StartTime; while (currentTime < entity.EndTime) { var currentDateTime = currentDate + currentTime; var appointment = _context.Appointments.Where(a => a.DateTime == currentDateTime && a.ProfessorID == entity.ProfessorID).Include(a => a.Professor).FirstOrDefault(); if (appointment != null) { if (appointment.Status != Appointment.StatusType.Open || appointment.Status != Appointment.StatusType.Cancelled) { AppointmentCancellation appointmentCancellation = new AppointmentCancellation { FirstName = appointment.FirstName, LastName = appointment.LastName, DateTime = appointment.DateTime, Created = DateTime.Now, Status = appointment.Status, Reason = "Professor Cancelled Office Hour", Email = appointment.Email, ProfessorID = appointment.ProfessorID }; emailAppointmentCancelled(appointment); } _context.Appointments.Remove(appointment); } currentTime = currentTime.Add(appointmentLength); } _context.SaveChanges(); } currentDate = currentDate.AddDays(1); } }