public async Task <IActionResult> Create([Bind("Id,SurName,Name,Patronymic,UserId")] Admin admin) { if (ModelState.IsValid) { _context.Add(admin); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", admin.UserId); return(View(admin)); }
public async Task <IActionResult> Create([Bind("Id,WorkId,UserId")] Work_User work_User) { if (ModelState.IsValid) { _context.Add(work_User); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["WorkId"] = new SelectList(_context.Works, "Id", "Id", work_User.WorkId); return(View(work_User)); }
public async Task <IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email); if (user == null) { User regUser = new User { Email = model.Email, Password = model.Password, Login = model.Email }; await db.SaveChangesAsync(); await Authenticate(regUser.Login, regUser); // аутентификация return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Некорректные логин и(или) пароль"); } } return(View(model)); }