public ActionResult Create([Bind(Exclude = "ProductID")] Product product) { if (ModelState.IsValid) { string rootPath = Server.MapPath("~/"); string fileName = System.IO.Path.GetFileName(product.ImagePath); product.ImagePath = fileName; product.DateAdd = DateTime.Now.ToString(); product.Status = "AVAILABLE"; _context.Products.InsertOnSubmit(product); _context.SubmitChanges(); } return(Json(product, JsonRequestBehavior.AllowGet)); }
public ActionResult Index(RegisterModel model) { var result = new AccountModel().IsNameExitst(model.UserName); if (ModelState.IsValid) { if (!result) { Account account = new Account { UserName = model.UserName, Password = model.Password }; _context.Accounts.InsertOnSubmit(account); _context.SubmitChanges(); TempData["Message"] = "Register success"; } else { ModelState.AddModelError("", "Your name was availible!"); } } return(View(model)); }