public ActionResult Create([Bind(Include = "Name,Description,Quantity,Price,ProductID")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
public ActionResult Register(User NewUser) { CoffeShopDBEntities ORM = new CoffeShopDBEntities(); if (ModelState.IsValid) { ORM.Users.Add(NewUser); ORM.SaveChanges(); ViewBag.UserList = ORM.Users.ToList(); //return RedirectToAction("AddUser"); ViewBag.Message = $"Hello {NewUser.FirstName} and Thank you for Registering with US! "; return(View("Result")); } else { ViewBag.Address = Request.UserHostAddress; return(View("Error")); } }
public ActionResult Welcome(Customer data) { CoffeShopDBEntities ORM = new CoffeShopDBEntities(); if (ModelState.IsValid) { try { ORM.Customers.Add(data); ORM.SaveChanges(); ViewBag.Message = $"Welcome {data.FirstName}! Your acccount was created successfully"; } catch (Exception e) { ViewBag.Message = $"Error: {e.Message} occured. Please try creating an account later"; //$"{data.Email} was not a valid customer"; } } return(View()); }