Exemple #1
0
        public List <IProfileTypeDto> GetAllProfileTypes()
        {
            List <IProfileTypeDto> profileTypes = new List <IProfileTypeDto>();

            SqlConnection conn = webShopContext.GetConnection();

            try
            {
                conn.Open();

                string        sql = "SELECT profile_type_id, profile_type_name FROM profiletype;";
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    profileTypes.Add(
                        new ProfileTypeDto()
                    {
                        ProfileTypeID   = rdr.GetInt32(0),
                        ProfileTypeName = rdr.GetString(1),
                    }
                        );
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            conn.Close();

            return(profileTypes);
        }
Exemple #2
0
        public List <ICategoryDto> GetAllCategories()
        {
            List <ICategoryDto> categories = new List <ICategoryDto>();

            SqlConnection conn = webShopContext.GetConnection();

            try
            {
                conn.Open();

                string        sql = "SELECT category_id, category_name FROM category;";
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    categories.Add(
                        new CategoryDto()
                    {
                        CategoryId   = rdr.GetInt32(0),
                        CategoryName = rdr.GetString(1),
                    }
                        );
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            conn.Close();

            return(categories);
        }
        public IShoppingCartDto GetShoppingCartById(int id)
        {
            SqlConnection conn = webShopContext.GetConnection();

            IShoppingCartDto shoppingCart = null;

            try
            {
                conn.Open();

                string     sql = "SELECT profile_id, product_id, amount FROM shoppingcart WHERE profile_id = @id;";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", id);
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    shoppingCart = new ShoppingCartDto()
                    {
                        ProfileID = rdr.GetInt32(0),
                        ProductID = rdr.GetInt32(1),
                        Amount    = rdr.GetInt32(2),
                    };
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            conn.Close();

            return(shoppingCart);
        }
Exemple #4
0
        public IProfileDto GetProfileById(int id)
        {
            SqlConnection conn = webShopContext.GetConnection();

            IProfileDto profile = null;

            try
            {
                conn.Open();

                string sql = "SELECT profile_id, email, first_name, insertion, last_name, zipcode, house_number, " +
                             "house_number_addition, password, profile_type_id FROM profile WHERE profile_id = @id;";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", id);
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    profile = new ProfileDto()
                    {
                        ID                  = rdr.GetInt32(0),
                        Email               = rdr.GetString(1),
                        FirstName           = rdr.GetString(2),
                        Insertion           = rdr.GetString(3),
                        LastName            = rdr.GetString(4),
                        ZipCode             = rdr.GetString(5),
                        HouseNumber         = rdr.GetInt32(6),
                        HouseNumberAddition = rdr.GetString(7),
                        Password            = rdr.GetString(8),
                        ProfileTypeID       = rdr.GetInt32(9),
                    };
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            conn.Close();

            return(profile);
        }
Exemple #5
0
        public List <IProductDto> GetAllProducts()
        {
            List <IProductDto> products = new List <IProductDto>();

            SqlConnection conn = webShopContext.GetConnection();

            try
            {
                conn.Open();

                string        sql = "SELECT id, name, description, price, image_path, category_id FROM product;";
                SqlCommand    cmd = new SqlCommand(sql, conn);
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    products.Add(
                        new ProductDto()
                    {
                        ProductID   = rdr.GetInt32(0),
                        Name        = rdr.GetString(1),
                        Description = rdr.GetString(2),
                        Price       = rdr.GetDecimal(3),
                        ImagePath   = !rdr.IsDBNull(4) ? rdr.GetString(4) : null,
                        CategoryID  = rdr.GetInt32(5),
                    }
                        );
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            conn.Close();

            return(products);
        }