public ActionResult Register(RegistViewModel model) { if (ModelState.IsValid) { User user = null; using (BotAppContext db = new BotAppContext()) { user = db.Users.FirstOrDefault(u => u.Login == model.Login); } if (user == null) { // создаем нового пользователя using (BotAppContext db = new BotAppContext()) { db.Users.Add(new User { Login = model.Login, Password = model.Password, Name = model.UserName, RoleId = 2 }); db.SaveChanges(); user = db.Users.Where(u => u.Login == model.Login && u.Password == model.Password).FirstOrDefault(); } // если пользовател успешно добавлен в БД if (user != null) { FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("AddToken", "LongPollServer")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(model)); }
static void Main() { if (File.Exists(BotAppContext.IconFileName)) { if (!SingleInstance.Start()) { return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { var applicationContext = new BotAppContext(); Application.Run(applicationContext); } catch (Exception ex) { MessageBox.Show(ex.Message, "Program Terminated Unexpectedly", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(ex.Message + " " + ex.StackTrace); } SingleInstance.Stop(); } else { MessageBox.Show("No program icon"); } }
public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { // поиск пользователя в бд User user = null; using (BotAppContext db = new BotAppContext()) { user = db.Users.FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("AddToken", "LongPollServer")); } else { ModelState.AddModelError("", "Поьзователя с таким логином и паролем нет в базе"); } } return(View(model)); }
public PaymentsController(BotAppContext context) { _context = context; }