public AppointmentContract InsertAppointment(int doctorId, int patientId, DateTime dateStart, DateTime dateEnd) { try { var isExist = context.GetAppointments(doctorId, patientId, dateStart, dateEnd).ToList().Any(); var failedModel = new AppointmentContract { Success = false }; if (isExist) { failedModel.Available = false; failedModel.ErrorMessage.Add("Schedule already taken"); return(failedModel); } var doctorDetails = context.GetUser(doctorId); var patientDetails = context.GetUser(patientId); if (doctorDetails == null || doctorDetails.UserTypeNo != (int)UserType.Doctor) { failedModel.ErrorMessage.Add("Appointed doctor is not valid."); } if (patientDetails == null || patientDetails.UserTypeNo != (int)UserType.Patient) { failedModel.ErrorMessage.Add("Appointed patient is not valid."); } var appointment = context.InsertAppointment(doctorId, patientId, dateStart, dateEnd); if (appointment.AppointmentId > 0) { return(mapper.Map <AppointmentContract>(appointment)); } else { failedModel.ErrorMessage.Add("Failed creating appointment"); return(failedModel); } } catch (Exception ex) { throw new ApplicationException("Failed creating appointment!", ex); } }
public AppointmentContract UpdateAppoint(int appointmentId, bool attended) { try { var appointment = context.UpdateAppointment(appointmentId, attended); var failedModel = new AppointmentContract(); if (appointment.AppointmentId > 0 && appointment.Attended == attended) { var dto = mapper.Map <AppointmentContract>(appointment); dto.Success = true; return(dto); } else { failedModel.ErrorMessage.Add("Failed updating appointment!"); return(failedModel); } } catch (Exception ex) { throw new ApplicationException("Failed updating appointment!", ex); } }