public async Task <AppointmentModel> CreateAppointment(AppointmentModel model) { var room = await _dbContext.WaitingRooms.Where(item => item.Id == model.RoomId).FirstOrDefaultAsync(); if (!room.UsePasscode || room.RoomCode == model.RoomCode) { var appointment = model.MapTo <Appointment>(); appointment.ProviderId = room.ProviderId; appointment.RoomId = room.Id; _dbContext.DoctorAppointments.Add(appointment); await _dbContext.SaveChangesAsync(); model.AppointmentId = appointment.Id; return(model); } else { throw new GenericException(ErrorCodes.GetCode("IncorrectRoomCode")); } }