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> /// Converts a timeslot, excluding apointment information to a Domain Model version of it. /// </summary> /// <param name="DbTimeSlot">A DB timeslot to be converted</param> /// <returns>The domain model version of a DB timeslot</returns> internal static Models.Timeslot MapTimeslot(DataModel.Timeslot DbTimeSlot) { Models.Timeslot timeslot = new Models.Timeslot(); //TODO: get timeslot from db when added to db timeslot.Id = DbTimeSlot.Id; timeslot.Start = DbTimeSlot.Start; timeslot.End = DbTimeSlot.End; return(timeslot); }