コード例 #1
0
ファイル: CenterDAO.cs プロジェクト: fabricekfr/Traca
        public override ICenter MapRecord(SQLiteDataReader dataReader)
        {
            var center = _DomainObjectsFactory.CreateCenter();

            center.Id              = dataReader.GetInt32(dataReader.GetOrdinal(nameof(ICenter.Id)));
            center.Name            = (string)dataReader[nameof(ICenter.Name)];
            center.StreetAddress   = dataReader[nameof(ICenter.StreetAddress)].GetType() != typeof(DBNull) ? (string)dataReader[nameof(ICenter.StreetAddress)] : string.Empty;
            center.CenterTypeId    = dataReader.GetInt32(dataReader.GetOrdinal(nameof(ICenter.CenterTypeId)));
            center.CenterTypeValue = (string)dataReader[nameof(ICenter.CenterTypeValue)];

            return(center);
        }
コード例 #2
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.");
        }