Example #1
0
        public async Task <IActionResult> Create([Bind("id,Name")] ProdactType prodactType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prodactType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(prodactType));
        }
        public async Task <IActionResult> Create([Bind("id,Name,Salers,ProdactType, Weight, Count, Price")] Prodacts prodacts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prodacts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(prodacts));
        }
Example #3
0
        public async Task <IActionResult> AddUser(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                //User user = await _context.Users.
                //    FirstOrDefaultAsync(u => u.Login == model.Login);
                if (!_context.Users.Any(u => u.Login == model.Login))
                {
                    var user = new User {
                        Login = model.Login, Password = model.Password
                    };
                    _context.Users.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }