Пример #1
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.Users.Add(new User {
                        Email = model.Email, Password = model.Password
                    });
                    await db.SaveChangesAsync();

                    await Authenticate(model.Email); // аутентификация

                    return(RedirectToAction("Index", "Dishes"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("DishID,Title,Recipe,Category")] Dish dish, int[] selectedIngridients)
        {
            if (ModelState.IsValid)
            {
                _context.Dishes.Add(dish);
                foreach (var m in selectedIngridients)
                {
                    _context.Dish_Ingridents.Add(new Dish_Ingrident {
                        Dish = dish, Ingridient = _context.Ingridients.Find(m)
                    });
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dish));
        }