Beispiel #1
0
        public List <ProductDal> GetProducts(int skip, int take)
        {
            List <ProductDal> proposedReturnValue = new List <ProductDal>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("GetProducts", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Skip", skip);
                    command.Parameters.AddWithValue("@Take", take);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ProductMapper m = new ProductMapper(reader);
                        while (reader.Read())
                        {
                            ProductDal r = m.ProductFromReader(reader);
                            proposedReturnValue.Add(r);
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(proposedReturnValue);
        }
Beispiel #2
0
        //product
        public ProductDal FindProductByID(int ProductID)
        {
            ProductDal ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("FindProductByID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@productID", ProductID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ProductMapper m     = new ProductMapper(reader);
                        int           count = 0;
                        while (reader.Read())
                        {
                            ProposedReturnValue = m.ProductFromReader(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new Exception($"Found more than 1 User with key{ProductID}");
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }
Beispiel #3
0
        public ProductDal ProductFromReader(System.Data.SqlClient.SqlDataReader reader)
        {
            ProductDal ProposedReturnValue = new ProductDal();

            ProposedReturnValue.ProductsID     = reader.GetInt32(OffsetToProductsID);
            ProposedReturnValue.CategoryID     = reader.GetInt32(OffsetToCategoryID);
            ProposedReturnValue.SellerID       = reader.GetInt32(OffsetToSellerID);
            ProposedReturnValue.Name           = reader.GetString(OffsetToName);
            ProposedReturnValue.Descrption     = reader.GetString(OffsetToDescription);
            ProposedReturnValue.ReservePrice   = reader.GetDecimal(OffsetToReserveprice);
            ProposedReturnValue.WinningofferID = Getint32OrDefault(reader, OffsetToWinningOffer);
            ProposedReturnValue.Comments       = reader.GetString(OffsetToComments);
            ProposedReturnValue.Photos         = GetstringOrDefault(reader, OffsetToPhotos);
            ProposedReturnValue.Categories     = reader.GetString(OffersetToCategories);
            ProposedReturnValue.SellerEmail    = reader.GetString(OffersetToSellerEmail);
            ProposedReturnValue.SellerName     = reader.GetString(OffersetToSellerName);
            return(ProposedReturnValue);
        }