public IActionResult AddChef(Chef newChef) { if (ModelState.IsValid) { DbContext.Add(newChef); DbContext.SaveChanges(); return(RedirectToAction("Index")); } else { return(View("newChef")); } }
static void Main(string[] args) { using (Mycontext db = new Mycontext()) { //Item it = new Item() { itemName = "steve" }; //db.Add(it); //db.SaveChanges(); Order o = new Order() { itemId = 2, orderdate = new DateTime(2019, 11, 2), deliverydate = DateTime.Parse("11-11-2019") }; db.Add(o); db.SaveChanges(); } }
public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (_context.Users.Any(e => e.Email == newUser.Email)) { ModelState.AddModelError("Email", "Email is already in use!"); return(View("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); newUser.Password = Hasher.HashPassword(newUser, newUser.Password); _context.Add(newUser); _context.SaveChanges(); HttpContext.Session.SetInt32("logged_in", newUser.UserId); return(RedirectToAction("Dashboard")); } } else { return(View("Index")); } }