public ActionResult Create([Bind(Include = "adminID, adminName, email, password, confirmPassword")] Admin admin) { try { if (ModelState.IsValid) { Admin admins = new Admin(); admins.adminName = admin.adminName; admins.email = admin.email; admins.password = Cipher.Encrypt(admin.password); admins.confirmPassword = Cipher.Encrypt(admin.confirmPassword); BuyalotDbContext Context = new BuyalotDbContext(); Context.Admins.Add(admins); Context.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /*dex*/) { //Log the error (uncomment dex variable name after DataException and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, contact your system administrator."); } return(View(admin)); }
public ActionResult Create(/*[Bind(Include = "ProductID,ProductName,ProductDescription,ProdCategoryID,Price,Vendor,QuantityInStock,ProductImage")]*/ Product product, FormCollection collection, HttpPostedFileBase upload) { if (ModelState.IsValid) { if (upload != null) { product.ProductImage = new byte[upload.ContentLength]; upload.InputStream.Read(product.ProductImage, 0, upload.ContentLength); } db.Products.Add(product); db.SaveChanges(); ViewBag.result = "Product " + product.Vendor + " " + product.ProductName + " Added Succesfully!"; return(RedirectToAction("Index")); } ViewBag.ProdCategoryID = new SelectList(db.ProductCategories, "ProdCategoryID", "CategoryName", product.ProdCategoryID); return(View(product)); }
public void Save() { context.SaveChanges(); }