Ejemplo n.º 1
0
        public Productmodel GetProductbyId(int productId)
        {
            string connectionString = "Server=DESKTOP-JA9OFG0\\SQLEXPRESS;Database=AAClothing;Trusted_Connection=True;";

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Product WHERE @productId = productId", connection))
                {
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.Parameters.AddWithValue("@Productid", productId);
                    using (SqlDataReader reader = sqlCommand.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            Productmodel prod = new Productmodel(productId);
                            while (reader.Read())
                            {
                                prod.Productnaam         = reader["ProductNaam"].ToString();
                                prod.Productprijs        = (double)reader["Productprijs"];
                                prod.Productbeschrijving = reader["Productbeschrijving"].ToString();
                            }
                            return(prod);
                        }
                        else
                        {
                            return(new Productmodel(-1));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public IActionResult productdetails(int id)
        {
            Productmodel product = GetProductbyId(id);

            product.Productid = id;
            return(View(product));
        }
        public async Task <ActionResult <Productmodel> > PostProductmodel(Productmodel productmodel)
        {
            _context.Productmodel.Add(productmodel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductmodel", new { id = productmodel.ModelId }, productmodel));
        }
        public async Task <IActionResult> PutProductmodel(byte id, Productmodel productmodel)
        {
            if (id != productmodel.ModelId)
            {
                return(BadRequest());
            }

            _context.Entry(productmodel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductmodelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 5
0
        public ProductDTO ConvertToDTO(Productmodel p)
        {
            ProductId           = p.Productid;
            ProductNaam         = p.Productnaam;
            ProductPrijs        = p.Productprijs;
            ProductImage        = p.ProductImage;
            ProductVoorraad     = p.ProductVoorraad;
            ProductBeschrijving = p.Productbeschrijving;

            return(this);
        }
Ejemplo n.º 6
0
        Productmodel ProductDetailsMapper(DataRow Row)
        {
            var ProductDetail = new Productmodel()
            {
                productID   = Row.ItemArray[0].ToString(),
                ProductName = Row.ItemArray[1].ToString(),
                Price       = Row.ItemArray[2].ToString(),
            };

            return(ProductDetail);
        }
Ejemplo n.º 7
0
        public List <Productmodel> InsertRecord(Productmodel MODEL)
        {
            var result = new List <Productmodel>();

            if (MODEL == null)
            {
                return(result);
            }
            try
            {
                using (SqlConnection sqlCon = new SqlConnection(Startup.ConnectionString))
                {
                    string insertdata = string.Format("Insert Into Product (productID, ProductName, Price) Values('{0}', '{1}', '{2}')", MODEL.productID, MODEL.ProductName, MODEL.Price);
                    using (SqlCommand cmd = new SqlCommand(insertdata, sqlCon))
                    {
                        sqlCon.Open();
                        cmd.ExecuteNonQuery();
                        sqlCon.Close();
                    }

                    using (SqlCommand cmd = new SqlCommand("SELECT * FROM Product", sqlCon))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();
                        DataSet        ds = new DataSet();



                        sqlCon.Open();
                        DataTable dt = new DataTable();
                        dt.Load(cmd.ExecuteReader());
                        //da = new SqlDataAdapter(cmd);

                        //da.Fill(ds);


                        result = FillModel(dt);
                        sqlCon.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(result);
        }
Ejemplo n.º 8
0
        public IActionResult Index()
        {
            List <Productmodel> products   = new List <Productmodel>();
            DataSet             sqlDataSet = new DataSet();

            string connectionString = "Server=DESKTOP-JA9OFG0\\SQLEXPRESS;Database=AAClothing;Trusted_Connection=True;";

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Product", connection))
                    using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
                    {
                        sqlDataAdapter.SelectCommand = sqlCommand;
                        sqlDataAdapter.Fill(sqlDataSet);
                    }
            }

            foreach (DataRow dr in sqlDataSet.Tables[0].Rows)
            {
                if (products.Where(p => p.Productid == (int)dr["Productid"]).ToList().Count == 0)
                {
                    Productmodel product = new Productmodel()
                    {
                        Productid           = (int)dr["Productid"],
                        Productnaam         = dr["Productnaam"].ToString(),
                        Productprijs        = (double)dr["Productprijs"],
                        Productbeschrijving = dr["Productbeschrijving"].ToString()

                                              //ProductImage = (byte[])dr["ProductImage"],
                    };

                    products.Add(product);
                }
                else
                {
                    //products.FirstOrDefault(id => id.ProductId == (long)dr["ProductId"]).ProductCategories.Add(dr["ProductCategoryName"].ToString());
                }
            }
            return(View(products));
        }