public ActionResult Create(IFormCollection collection)//根据 表单信息保存
        {
            //Product product = new Product();
            //PRopertyInfo[] propertyInfo = typeof(Product).GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags)
            //foreach(PropertyInfo p in propertyInfo)
            //{

            //}
            try
            {
                Product product = new Product();
                product.ProductName   = collection["ProductName"];
                product.Brand         = collection["Brand"];
                product.StockQuantity = int.Parse(collection["StockQuantity"]);
                product.Price         = decimal.Parse(collection["Price"]);
                product.Spec          = collection["Spec"];
                product.Description   = collection["Description"];
                product.ManufactorId  = int.Parse(collection["ManufactorId"]);

                //然后把商品添加到商品集合中去
                _context.Product.Add(product);

                //保存到数据库
                _context.SaveChanges();  //自动生成insert 语句


                return(RedirectToAction(nameof(Index)));  //如果保存成功的话 跳转到商品列表
            }
            catch
            {
                return(View()); //不成功的话 返回列表页面
            }
        }
Beispiel #2
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                User user = new User();
                user.UserId       = collection["UserID"];
                user.Pwd          = collection["Pwd"];
                user.UserName     = collection["UserName"];
                user.NickName     = collection["NickName"];
                user.ManufactorId = int.Parse(collection["ManufactorId"]);

                //然后把商品添加到商品集合中去
                _context.User.Add(user);

                //保存到数据库
                _context.SaveChanges();  //自动生成insert 语句

                // TODO: Add insert logic here

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #3
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                Manufactor manufactor = new Manufactor();

                manufactor.Id          = int.Parse(collection["Id"]);
                manufactor.CompanyName = collection["CompanyName"];
                manufactor.Address     = collection["Address"];
                manufactor.Province    = collection["Province"];
                manufactor.City        = collection["City"];
                manufactor.ContactTel  = collection["ContactTel"];
                manufactor.RegistDate  = DateTime.Parse(collection["RegistDate"]);
                manufactor.Status      = collection["Status"];
                //数据库里面的数据类型是char 但是Models里面的数据类型是String

                _context.Manufactor.Add(manufactor);

                //保存到数据库
                _context.SaveChanges();  //自动生成insert 语句

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
 public ActionResult Create(IFormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         Product product = new Product();
         product.ProductName   = collection["ProductName"];
         product.Brand         = collection["Brand"];
         product.Price         = decimal.Parse(collection["Price"]);
         product.StockQuantity = int.Parse(collection["StockQuantity"]);
         product.Spec          = collection["Spec"];
         product.ManufactorId  = int.Parse(collection["ManufactorId"]);
         product.Description   = collection["Description"];
         _context.Product.Add(product);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }