示例#1
0
        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);
        }
            public void Add()
            {
                var timeslot = new Models.Timeslot
                {
                    StartTime   = new DateTime(2018, 5, 21, 4, 0, 0),
                    EndTime     = new DateTime(2018, 5, 21, 5, 0, 0),
                    Description = "First Timeslot",
                };

                Console.WriteLine(EventsXdService.SessionTimes.Add(5577, timeslot));
            }
            public void Update()
            {
                var timeslot = new Models.Timeslot
                {
                    StartTime   = new DateTime(2018, 5, 21, 4, 30, 0),
                    EndTime     = new DateTime(2018, 5, 21, 7, 30, 0),
                    Description = "Second Timeslot2",
                    Id          = "78043"
                };

                Console.WriteLine(EventsXdService.SessionTimes.Update(5577, 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);
        }
示例#5
0
        /*    _    _      _
         *   | |  | |    | |
         *   | |__| | ___| |_ __   ___ _ __ ___
         *   |  __  |/ _ \ | '_ \ / _ \ '__/ __|
         *   | |  | |  __/ | |_) |  __/ |  \__ \
         *   |_|  |_|\___|_| .__/ \___|_|  |___/
         *                 | |
         *                 |_|
         */
        #region PrivateHelpers
        /// <summary>
        /// Takes a list of db timeslots and converts them to apointments
        /// </summary>
        /// <param name="timeslots">List of DB timeslots</param>
        /// <returns>List of model timeslots</returns>
        private static List <Models.Timeslot> ConvertTimeslots(List <DataModel.Timeslot> timeslots, bool AllowNullApointmentsFlag = false)
        {
            List <Models.Timeslot> modelTimeslots = new List <Models.Timeslot>();

            foreach (var DBTimeSlot in timeslots)
            {
                Models.Timeslot modelts = DB_DomainMapper.MapTimeslot(DBTimeSlot);

                //does not fill in dr or patient
                if (DBTimeSlot.Appointment is not null)
                {
                    modelts.Appointment = DB_DomainMapper.MapApointment(DBTimeSlot.Appointment);
                }
                else if (AllowNullApointmentsFlag)
                {
                    throw new NullReferenceException("A timeslot has a null apointment reference");
                }

                modelTimeslots.Add(modelts);
            }

            return(modelTimeslots);
        }