コード例 #1
0
        public string AddAppointment(AppointmentPostDataContract appointmentPostDataContract)
        {
            if (appointmentPostDataContract == null)
            {
                throw new ArgumentNullException(nameof(appointmentPostDataContract));
            }

            DateTime date;

            if (!DateTime.TryParseExact(appointmentPostDataContract.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
            {
                throw new WebFaultException <string>($"ERROR : The expected date format is YYYY-MM-DD but was {appointmentPostDataContract.Date}!", HttpStatusCode.BadRequest);
            }

            if (_CenterDAO.GetById(appointmentPostDataContract.CenterId) == null)
            {
                throw new WebFaultException <string>($"ERROR : The center #{appointmentPostDataContract.CenterId} not exist!", HttpStatusCode.BadRequest);
            }

            if (_AppointmentDAO.GetByCenterAndByDate(appointmentPostDataContract.CenterId, date) != null)
            {
                throw new WebFaultException <string>($"ERROR : This date {appointmentPostDataContract.Date} has already been booked for the center #{appointmentPostDataContract.CenterId}!", HttpStatusCode.Conflict);
            }

            var appointment = _DomainObjectsFactory.CreateAppointment();

            appointment.ClientFullName = appointmentPostDataContract.ClientFullName;
            appointment.Date           = date;
            appointment.Center         = _DomainObjectsFactory.CreateCenter();
            appointment.Center.Id      = appointmentPostDataContract.CenterId;
            var numberOfRows = _AppointmentDAO.Add(appointment);

            if (numberOfRows == 0)
            {
                throw new WebFaultException <string>("ERROR : Unable to add a new appointment with given information!", HttpStatusCode.InternalServerError);
            }

            return("SUCCESS : The appointment has been added.");
        }
コード例 #2
0
ファイル: AppointmentDAO.cs プロジェクト: fabricekfr/Traca
        public override IAppointment MapRecord(SQLiteDataReader dataReader)
        {
            var appointment = _DomainObjectsFactory.CreateAppointment();

            appointment.Id                     = dataReader.GetInt32(dataReader.GetOrdinal(nameof(IAppointment.Id)));
            appointment.ClientFullName         = (string)dataReader[nameof(IAppointment.ClientFullName)];
            appointment.Date                   = (DateTime)dataReader[nameof(IAppointment.Date)];
            appointment.Center.Id              = dataReader.GetInt32(dataReader.GetOrdinal(nameof(IAppointment.Center)));
            appointment.Center.Name            = (string)dataReader[nameof(ICenter.Name)];
            appointment.Center.StreetAddress   = dataReader[nameof(ICenter.StreetAddress)].GetType() != typeof(DBNull) ? (string)dataReader[nameof(ICenter.StreetAddress)] : string.Empty;
            appointment.Center.CenterTypeId    = dataReader.GetInt32(dataReader.GetOrdinal(nameof(ICenter.CenterTypeId)));
            appointment.Center.CenterTypeValue = (string)dataReader[nameof(ICenter.CenterTypeValue)];

            return(appointment);
        }