public ActionResult Registr(Registr reg) { if (ModelState.IsValid) { using (watcherEntities data = new watcherEntities()) { var EmailRepeating = data.User_reg.Where(x => x.email == reg.email).ToList(); if (EmailRepeating.Count > 0) { ModelState.AddModelError("Repeat", "This email has already exist,please change this email"); } User_reg user = new User_reg(); user.name = reg.name; user.surname = reg.surname; user.age = reg.age; user.email = reg.email; user.phone = reg.phone; user.password = reg.password; data.User_reg.Add(user); data.SaveChanges(); Response.Write("<script>alert(Success,Registration successfully done.)</script>"); } } return(View()); }
public ActionResult Login(User_reg logs, string returnurl) { if (ModelState.IsValid) { using (watcherEntities us = new watcherEntities()) { var log = us.User_reg.Where(x => x.name.Equals(logs.name) && x.password.Equals(logs.password)).FirstOrDefault(); if (log != null) { if (log.roleID == 1 && log.name == logs.name || log.password == logs.password) { Session["username"] = log.name; return(RedirectToAction("Home", "Admin", "Index")); } else if (log.roleID == 2 && log.name == logs.name || log.password == logs.password) { return(RedirectToAction("Economy", "Main")); } else { return(View("Error")); } } else { return(View("Error")); } } } return(View()); }