Пример #1
0
        /// <summary>
        /// Attempts to book a TC Service Center for a specific day under requestee name
        /// </summary>
        /// <remarks>
        /// 1. A valid TC Center must be requested.
        /// 2. TC Center must not exceed max accommodation per day
        /// </remarks>
        /// <param name="appointment"></param>
        /// <returns></returns>
        public OperationAddResult AddAppointment(Appointment appointment)
        {
            var center = _centerService.GetCenter(appointment.CenterId);

            //add center to appointment to allow for center object to be part of response.
            appointment.Center = center;

            if (center == null)
            {
                return(new OperationAddResult()
                {
                    Outcome = OperationAddResult.AppointmentOperation.CenterDoesNotExist, Appointment = appointment
                });
            }

            if (!IsServiceCenterAvailable(appointment, center))
            {
                return(new OperationAddResult()
                {
                    Outcome = OperationAddResult.AppointmentOperation.CenterAccommodationFull, Appointment = appointment
                });
            }

            AddOrUpdateAppointment(appointment);

            return(new OperationAddResult()
            {
                Outcome = OperationAddResult.AppointmentOperation.AppointmentCreated, Appointment = appointment
            });
        }
Пример #2
0
        /// <summary>
        /// Checks to see if a specific TC Service Center is available for accommodation on the requested date.
        /// </summary>
        /// <remarks>The Max Accomodation Quantity is set via Centers table in the db.</remarks>
        /// <param name="appointment"></param>
        /// <param name="center"></param>
        /// <returns></returns>
        private bool IsServiceCenterAvailable(Appointment appointment, DTO.Center center)
        {
            var numberOfAppointmentsOnCenter = _appointmentRepository.NumberOfAppointmentsOnCenter(
                appointment.CenterId, appointment.Date);

            return(numberOfAppointmentsOnCenter < center.MaxAccommodationQuantityPerDay);
        }
Пример #3
0
        /// <summary>
        /// Attempts to update an appointment
        /// </summary>
        /// <remarks>
        /// 1. Appointment must exist before updating
        /// 2. Valid exiting center on update must be requested.
        /// 3. TC Center must not exceed max accommodation per day
        /// </remarks>
        /// <param name="appointment"></param>
        /// <returns></returns>
        public OperationUpdateResult UpdateAppointment(Appointment appointment)
        {
            if (!DoesAppointmentExist(appointment.Id))
            {
                return(new OperationUpdateResult()
                {
                    Outcome = OperationUpdateResult.AppointmentOperation.AppointmentDoesNotExist, Appointment = appointment
                });
            }

            var center = _centerService.GetCenter(appointment.CenterId);

            if (center == null)
            {
                return(new OperationUpdateResult()
                {
                    Outcome = OperationUpdateResult.AppointmentOperation.CenterDoesNotExist, Appointment = appointment
                });
            }

            if (!IsServiceCenterAvailable(appointment, center))
            {
                return(new OperationUpdateResult()
                {
                    Outcome = OperationUpdateResult.AppointmentOperation.CenterAccommodationFull, Appointment = appointment
                });
            }


            AddOrUpdateAppointment(appointment);

            return(new OperationUpdateResult()
            {
                Outcome = OperationUpdateResult.AppointmentOperation.AppointmentUpdated, Appointment = appointment
            });
        }
Пример #4
0
 /// <summary>
 /// Adds or update appointment entity to db.
 /// </summary>
 /// <param name="appointment"></param>
 private void AddOrUpdateAppointment(Appointment appointment)
 {
     _appointmentRepository.AddOrUpdateAppointment(appointment);
 }