예제 #1
0
 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);
 }
예제 #2
0
        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));
        }
예제 #3
0
 public async Task SaveChanges()
 {
     await _context.SaveChangesAsync();
 }
예제 #4
0
 public async Task CreatePicture(Picture model)
 {
     _context.Pictures.Add(model);
     await _context.SaveChangesAsync();
 }