public ActionResult Create(tbl_Product products)
        {
            products.User_ID = Convert.ToInt32(Session["u_id"]);
            try
            {
                HttpPostedFileBase photo = Request.Files["Imagepath"];
                if (photo != null && photo.ContentLength > 0)
                {
                    var fileName = new Random().Next(100000000, 999999999) + Path.GetFileName(photo.FileName);
                    photo.SaveAs(Path.Combine(Server.MapPath("~") + "/Image/", fileName));
                    products.Product_Image = Path.Combine("/Image/", fileName);
                }
                // products.User_ID = 1;
                if (ModelState.IsValid)
                {
                    //var userid = 1;
                    //products.User_ID = userid;

                    db.tbl_Product.Add(products);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                ViewBag.Product_CategoryID = new SelectList(db.tbl_Product_Category, "Product_CategoryID", "Product_CategoryName", products.Product_CategoryID);
            }
            catch (Exception ex)
            {
                //something went wrong
            }
            return(View(products));
        }
        public ActionResult Create(tbl_Product_Category category)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Product_Category.Add(category);
                db.SaveChanges();
            }

            return(View(category));
        }
Пример #3
0
        public ActionResult Register(tbl_User user)
        {
            ElectronicsDbEntities db = new ElectronicsDbEntities();

            user.Role_ID = 2;
            user.AddedOn = DateTime.Now;

            //user.User_Gender = "Male";
            //user.User_Gender = "Female";
            //var gender=db.

            db.tbl_User.Add(user);
            db.SaveChanges();
            return(View());
        }