public ActionResult Login(LoginViewModel viewm) { bool valid = false; using (sandwichswapContext con = new sandwichswapContext()) { foreach (User u in con.Users) { if (u.username == viewm.Username) { if (u.password == viewm.Password) { valid = true; LoginUser = u; } } } } ActionResult r = null; if (valid) { r = new RedirectResult("Index"); } else { ModelState.AddModelError("Password", "Invald Password"); r = View(); } return(r); }
public ActionResult Register(User user) { using (sandwichswapContext con = new sandwichswapContext()) { con.Users.Add(user); con.SaveChanges(); } return(View("Index")); }
public ActionResult Menu() { List <Bread> breads = new List <Bread>(); List <Topping> toppings = new List <Topping>(); List <Sandwich> sandwiches = new List <Sandwich>(); List <PartialMenuViewModel> pms = new List <PartialMenuViewModel>(); using (sandwichswapContext con = new sandwichswapContext()) { breads = con.Breads.ToList(); toppings = con.Toppings.ToList(); sandwiches = con.Sandwiches.ToList(); foreach (Sandwich s in sandwiches) { pms.Add(new PartialMenuViewModel(s.username, s.sandwichname, s.Sandwich_Topping.ToList(), s.Bread, s.votes)); } } return(View(new MenuViewModel(breads, toppings, sandwiches, pms, LoginUser))); }
public void SaveSandwich(int breadId, int[] toppingIds, string sandwichName /*, string userName*/) { using (sandwichswapContext con = new sandwichswapContext()) { Sandwich s = new Sandwich(); s.Bread = con.Breads.Where(x => x.Id == breadId).Single(); for (int i = 1; i < toppingIds.Count(); i++) { Sandwich_Topping newtopping = new Sandwich_Topping(); newtopping.Sandwich = s; newtopping.ToppingId = toppingIds[i]; s.Sandwich_Topping.Add(newtopping); } s.User = con.Users.Where(x => x.username.Equals(LoginUser.username)).Single(); s.sandwichname = sandwichName; s.votes = 0; con.Sandwiches.Add(s); con.SaveChanges(); } }