public async Task<IActionResult> Create([Bind("Id,Name")] Cargo cargo) { if (ModelState.IsValid) { _context.Add(cargo); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(cargo); }
public async Task <IActionResult> Register(Register model) { if (ModelState.IsValid) { User user = await _context.Users.FirstOrDefaultAsync(u => u.Phone == model.Phone && u.FullName == model.FullName); if (user == null) { // добавляем пользователя в бд user = new User { Phone = model.Phone, Password = model.Password, FullName = model.FullName }; Role userRole = await _context.Roles.FirstOrDefaultAsync(r => r.Name == "user"); if (userRole != null) { user.Role = userRole; } _context.Users.Add(user); Client client = new Client { Name = model.FullName, Phone = model.Phone }; _context.Clients.Add(client); await _context.SaveChangesAsync(); await Authenticate(user); // аутентификация return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Некорректные логин и(или) пароль"); } } return(View(model)); }
public async Task SaveChanges() { await _context.SaveChangesAsync(); }
public async Task CreatePicture(Picture model) { _context.Pictures.Add(model); await _context.SaveChangesAsync(); }