Exemplo n.º 1
0
        public ItemDAL Item_FindByItemID(int itemID)
        {
            ItemDAL ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("Item_FindByItemID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ItemID", itemID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ItemMapper mapper = new ItemMapper(reader);
                        int        count  = 0;
                        while (reader.Read())
                        {
                            ProposedReturnValue = mapper.ItemFromReader(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new Exception($"Found more than 1 Item with key {itemID}");
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
                // No access to scope - Exception thrown before entering
            }
            return(ProposedReturnValue);
        }
Exemplo n.º 2
0
        public List <ItemDAL> Items_GetRelatedToUserID(int userID, int skip, int take)
        {
            List <ItemDAL> proposedReturnValue = new List <ItemDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("Items_GetRelatedToUserID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@UserID", userID);
                    command.Parameters.AddWithValue("@Skip", skip);
                    command.Parameters.AddWithValue("@Take", take);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ItemMapper mapper = new ItemMapper(reader);
                        while (reader.Read())
                        {
                            ItemDAL reading = mapper.ItemFromReader(reader);
                            proposedReturnValue.Add(reading);
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
                // No access to scope - Exception thrown before entering
            }
            return(proposedReturnValue);
        }