Exemplo n.º 1
0
        public Appointment CreateAppointment(AppointmentRequest request)
        {
            if (request.AppointmentDate.Date <= _dateTimeProvider.Today)
            {
                throw new Exception("Cannot make an appointment before today");
            }

            int maxDays = Convert.ToInt32(_configProvider.GetValueWithDefault("MaxDays", "30"));

            if (request.AppointmentDate.Date > _dateTimeProvider.Today.AddDays(maxDays))
            {
                throw new Exception($"Cannot make an appointment more than {maxDays} in the future");
            }


            var confirmationCode = _confirmCodeProvider.NewConfirmationCode();

            AppointmentDao dao  = new AppointmentDao();
            Appointment    appt = new Appointment()
            {
                ConfirmationCode   = confirmationCode,
                CustomerName       = request.CustomerName,
                CarDescription     = request.CarDescription,
                AppointmentDate    = request.AppointmentDate,
                Hours              = request.Hours,
                ServiceDescription = request.ServiceDescription,
                CreateTime         = _dateTimeProvider.Now,
                CreateUser         = _userProvider.CurrentUsername
            };

            dao.InsertAppointment(appt);

            return(appt);
        }
        public Appointment CreateAppointment(AppointmentRequest request)
        {
            if (request.AppointmentDate.Date <= this.Today)
            {
                throw new Exception("Cannot make an appointment before today");
            }

            int maxDays = this.MaxAppointmentDays;

            if (request.AppointmentDate.Date > this.Today.AddDays(maxDays))
            {
                throw new Exception($"Cannot make an appointment more than {maxDays} in the future");
            }


            var confirmationCode = this.GetConfirmationCode();

            AppointmentDao dao  = new AppointmentDao();
            Appointment    appt = new Appointment()
            {
                ConfirmationCode   = confirmationCode,
                CustomerName       = request.CustomerName,
                CarDescription     = request.CarDescription,
                AppointmentDate    = request.AppointmentDate,
                Hours              = request.Hours,
                ServiceDescription = request.ServiceDescription,
                CreateTime         = this.Now,
                CreateUser         = this.CurrentUserName
            };

            dao.InsertAppointment(appt);

            return(appt);
        }