public async Task <Appointment> AddAppointment(RegisterAppointmentModel appModel) { try { if (await IsAppointmentExist(appModel)) { throw new Exception("Appointment already exists, please try another hour"); } Appointment newApp = new Appointment() { GuidID = Guid.NewGuid(), UserName = appModel.UserName, CreatedOn = DateTime.Now, AppointmentDate = appModel.AppointmentDate.AddDays(1), AppointmentHour = appModel.AppointmentHour }; await _context.Appointments.AddAsync(newApp); await _context.SaveChangesAsync(); return(newApp); } catch (Exception e) { throw e; } }
public async Task <bool> IsAppointmentExist(RegisterAppointmentModel appModel) { var appList = await this.GetAppointments(); foreach (var item in appList) { if (appModel.AppointmentDate == item.AppointmentDate && appModel.AppointmentHour == item.AppointmentHour) { return(true); } } return(false); }
public async Task <object> CreateAppointment(RegisterAppointmentModel model) { try { if (await _appService.IsAppointmentExist(model)) { return(BadRequest(new { message = "Appointment is already exist" })); } var newApp = await _appService.AddAppointment(model); if (newApp != null) { return(Ok(newApp)); } return(BadRequest(new { message = "Operation failed, servers are down at the moment" })); } catch (Exception e) { return(BadRequest(new { e.Message })); } }
public async Task <bool> IsAppointmentExist(RegisterAppointmentModel appModel) { return(await _appointmentRepository.IsAppointmentExist(appModel)); }
public async Task <Appointment> AddAppointment(RegisterAppointmentModel model) { return(await _appointmentRepository.AddAppointment(model)); }