コード例 #1
0
        public List <ViolationsDAL> GetViolationsRelatedToObsID(int ObsID, int skip, int take)
        {
            List <ViolationsDAL> ProposedReturnValue = new List <ViolationsDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("GetViolationsRelatedToObsID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ObsID", ObsID);
                    command.Parameters.AddWithValue("@Skip", skip);
                    command.Parameters.AddWithValue("@Take", take);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ViolationsMapper m = new ViolationsMapper(reader);
                        while (reader.Read())
                        {
                            ViolationsDAL r = m.ViolationFromReader(reader);
                            ProposedReturnValue.Add(r);
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }
コード例 #2
0
        public ViolationsDAL FindViolationByViolationID(int ViolationID)
        {
            ViolationsDAL ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command
                           = new SqlCommand("FindViolationByViolationID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ViolationID", ViolationID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ViolationsMapper m = new ViolationsMapper(reader);
                        int count          = 0;
                        while (reader.Read())
                        {
                            ProposedReturnValue = m.ViolationFromReader(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new
                                  Exception($"Found more than 1 Violation with key   {ViolationID}");
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }