public HistoryDAL FindHistoryByID(int HistoryID)
        {
            HistoryDAL ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command
                           = new SqlCommand("FindHistoryByID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@HistoryID", HistoryID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        HistoryMapper m     = new HistoryMapper(reader);
                        int           count = 0;
                        while (reader.Read())
                        {
                            ProposedReturnValue = m.HistoryFromReader(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new
                                  Exception($"Found more than 1 History with key {HistoryID}");
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }
        public List <HistoryDAL> GetHistoryByPlateID(int PlateID, int skip, int take)
        {
            List <HistoryDAL> ProposedReturnValue = new List <HistoryDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("GetHistoryByPlateID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@PlateID", PlateID);
                    command.Parameters.AddWithValue("@Skip", skip);
                    command.Parameters.AddWithValue("@Take", take);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        HistoryMapper m = new HistoryMapper(reader);
                        while (reader.Read())
                        {
                            HistoryDAL r = m.HistoryFromReader(reader);
                            ProposedReturnValue.Add(r);
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }
Пример #3
0
        public HistoryDAL HistoryFromReader(System.Data.SqlClient.SqlDataReader reader)
        {
            HistoryDAL proposedReturnValue = new HistoryDAL();

            proposedReturnValue.HistoryID       = GetInt32OrDefault(reader, OffsetToHistoryID);
            proposedReturnValue.PlateID         = GetInt32OrDefault(reader, OffsetToPlateID);
            proposedReturnValue.PaidFine        = GetStringOrDefault(reader, OffsetToPaidFine);
            proposedReturnValue.RegisteredOwner = GetStringOrDefault(reader, OffsetToRegisteredOwner);
            proposedReturnValue.Address1        = GetStringOrDefault(reader, OffsetToAddress1);
            proposedReturnValue.State           = GetStringOrDefault(reader, OffsetToState);
            proposedReturnValue.ViolationID     = GetInt32OrDefault(reader, OffsetToViolationID);
            proposedReturnValue.ViolationDesc   = GetStringOrDefault(reader, OffsetToViolationDesc);
            proposedReturnValue.RecordSpeed     = GetInt32OrDefault(reader, OffsetToRecordSpeed);

            return(proposedReturnValue);
        }