public async Task <Models.Appointment> AddAppointmentToTimeslotAsync(Models.Appointment appointment, int TimeslotId) { var timeslot = await _context.Timeslots.FindAsync(TimeslotId); if (timeslot == null) { throw new ArgumentException($"Timeslot id:{TimeslotId} can't be modified because it doesn't exist"); } if (timeslot.AppointmentId is not null) { throw new ArgumentException($"Timeslot id:{TimeslotId} already has an appointment"); } var new_appointment = new DataModel.Appointment { DoctorId = appointment.DoctorId, PatientId = appointment.PatientId, Start = timeslot.Start, End = timeslot.End }; await _context.Appointments.AddAsync(new_appointment); await _context.SaveChangesAsync(); timeslot.AppointmentId = new_appointment.Id; appointment.Id = new_appointment.Id; await _context.SaveChangesAsync(); return(appointment); }
public async Task <Models.Timeslot> AddTimeslotAsync(Models.Timeslot timeslot) { DataModel.Timeslot DBTimeslot = new DataModel.Timeslot(); //DBTimeslot.Id = timeslot.Id; //todo: check if Id is valid in DB, and if not, throw some argument exception. DBTimeslot.DoctorId = timeslot.DoctorId; DBTimeslot.Start = timeslot.Start; DBTimeslot.End = timeslot.End; DBTimeslot.AppointmentId = timeslot.Appointment?.Id; //DBTimeslot.DoctorId = timeslot.dr.id; if (timeslot.Appointment is not null) { // TODO: construct appointment record and insert into table DataModel.Appointment appointment = new DataModel.Appointment { Notes = timeslot.Appointment.Notes, PatientId = timeslot.Appointment.PatientId, DoctorId = timeslot.Appointment.DoctorId, Start = timeslot.Start, End = timeslot.End }; await _context.Appointments.AddAsync(appointment); } await _context.Timeslots.AddAsync(DBTimeslot); _context.SaveChanges(); timeslot.Id = DBTimeslot.Id; return(timeslot); }
/// <summary> /// Map a DB apointment to an equivilent model apointment. Will not fill in doctor, or patient reference. /// </summary> /// <param name="Dbappointment">A DB version of the apointment to be converted.</param> /// <returns>A model version of the given apointment.</returns> internal static Models.Appointment MapApointment(DataModel.Appointment Dbappointment, Models.Doctor doctor = null) { return(new Models.Appointment(Dbappointment.Id, Dbappointment.Notes, doctor)); }