public int Create(ProductsForAdmin products)
        {
            SqlCommand cmd = new SqlCommand("CreateProducts", connection2);

            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                cmd.Parameters.AddWithValue("@1", products.ModelId);
                cmd.Parameters.AddWithValue("@2", products.Name);
                cmd.Parameters.AddWithValue("@3", products.SuppliersId);
                cmd.Parameters.AddWithValue("@4", products.CategoryId);
                cmd.Parameters.AddWithValue("@5", products.StoreLocationId);
                cmd.Parameters.AddWithValue("@6", products.ProductsDescription);
                cmd.Parameters.AddWithValue("@7", products.UnitsInStock);
                cmd.Parameters.AddWithValue("@8", products.UnitPrice);
                cmd.Parameters.AddWithValue("@9", products.Discount);
                cmd.Parameters.AddWithValue("@10", products.FinalPrice);
                cmd.Parameters.AddWithValue("@11", products.Size);
                cmd.Parameters.AddWithValue("@12", products.Colour);
                cmd.Parameters.AddWithValue("@13", products.EntryDate);

                int i = cmd.ExecuteNonQuery();

                return(i);
            }
            finally
            {
                cmd.Dispose();
            }
        }
        public ProductsForAdmin GetDetails(int id)
        {
            ProductsForAdmin products = new ProductsForAdmin();


            SqlCommand command = new SqlCommand("GetDetails", connection2);

            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@Id", id);
            using (SqlDataReader dataReader = command.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    var currentRow = dataReader;

                    products.Id                  = (int)currentRow["ProductsId"];
                    products.ModelId             = currentRow["ModelId"].ToString();
                    products.Name                = currentRow["ProductsName"].ToString();
                    products.SuppliersId         = (int)currentRow["Suppliers"];
                    products.CategoryId          = (int)currentRow["Category"];
                    products.StoreLocationId     = (int)currentRow["StoreLocation"];
                    products.Size                = currentRow["Size"].ToString();
                    products.EntryDate           = (DateTime)currentRow["EntryDate"];
                    products.ProductsDescription = currentRow["ProductsDescription"].ToString();
                    products.UnitsInStock        = (int)currentRow["UnitsInStock"];
                    products.Discount            = (decimal)currentRow["Discount"];
                    products.FinalPrice          = (decimal)currentRow["FinalPrice"];
                    products.UnitPrice           = (decimal)currentRow["UnitPrice"];
                    products.Colour              = currentRow["AvaibleColours"].ToString();
                }
            }

            return(products);
        }
        public ActionResult Edit(ProductsForAdmin rowModel, int id)
        {
            /* ProductsForAdmin rowModel = new ProductsForAdmin()
             * {
             *   ModelId = productRow.Id,
             *   ProductsName = productRow.Name,
             *   SuppliersId = productRow.Suppliers,
             *   CategoryId = productRow.Category,
             *   StoreLocationId = productRow.Store,
             *   ProductsDescription = productRow.Description,
             *   UnitsInStock = productRow.Stock,
             *   UnitPrice = productRow.UnitPrice,
             *   Discount = productRow.Discount,
             *   FinalPrice = productRow.Price,
             *   Size = productRow.Size,
             *   Colour = productRow.Colour,
             *   EntryDate = productRow.EntryDate
             * };*/
            if (prodCreate.Update(rowModel, id) >= 1)
            {
                ViewBag.Message = "Student Details Updated Successfully";
                ModelState.Clear();
                return(RedirectToAction("Index"));
            }


            return(View());
        }
        public ActionResult Create(ProductsRowModel productRow)
        {
            ProductsForAdmin rowModel = new ProductsForAdmin()
            {
                ModelId             = productRow.Id,
                Name                = productRow.Name,
                SuppliersId         = productRow.Suppliers,
                CategoryId          = productRow.Category,
                StoreLocationId     = productRow.Store,
                ProductsDescription = productRow.Description,
                UnitsInStock        = productRow.Stock,
                UnitPrice           = productRow.UnitPrice,
                Discount            = productRow.Discount,
                FinalPrice          = productRow.Price,
                Size                = productRow.Size,
                Colour              = productRow.Colour,
                EntryDate           = productRow.EntryDate
            };

            prodCreate.Create(rowModel);


            ViewBag.Message = "Student Details Added Successfully";
            ModelState.Clear();
            return(RedirectToAction("Create"));
        }
        public ActionResult Details(int id)
        {
            // entity from database
            ProductsForAdmin allproducts = this.prodCreate.GetDetails(id);
            // model for view
            ProductsRowModel list = new ProductsRowModel()
            {
                ProductId   = allproducts.Id,
                Name        = allproducts.Name,
                Colour      = allproducts.Colour,
                Suppliers   = allproducts.SuppliersId,
                Category    = allproducts.CategoryId,
                Store       = allproducts.StoreLocationId,
                Size        = allproducts.Size,
                EntryDate   = allproducts.EntryDate,
                Description = allproducts.ProductsDescription,
                Stock       = allproducts.UnitsInStock,
                Discount    = allproducts.Discount,
                Price       = allproducts.FinalPrice,
                UnitPrice   = allproducts.UnitPrice
            };

            return(View(list));
        }