コード例 #1
0
ファイル: PersonalController.cs プロジェクト: AynurZ/B4P
        public async Task <IActionResult> Change(string email, string login, string name, string family,
                                                 string lastname, DateTime birthday, string phone)
        {
            var user = await _context.Users.FirstOrDefaultAsync(p => p.UserId == int.Parse(User.Identity.Name));

            user.UserMail     = email;
            user.UserLogin    = login;
            user.UserName     = name;
            user.UserFamily   = family;
            user.UserLastName = lastname;
            user.UserBirthday = birthday;
            user.UserPhone    = phone;
            await _context.SaveChangesAsync();

            return(RedirectToAction("Data", "Personal"));
        }
コード例 #2
0
        public async Task AddGood(int goodId)
        {
            Basket goodInBasket = await _context.Basket.FirstOrDefaultAsync(u => u.GoodsId == goodId);

            if (goodInBasket == null)
            {
                goodInBasket = new Basket {
                    UserId = int.Parse(User.Identity.Name), GoodsId = goodId, SizeId = 1, Amount = 1
                };
                _context.Basket.Add(goodInBasket);
                await _context.SaveChangesAsync();

                RedirectToAction("Goods", "Home");
            }
            else
            {
                goodInBasket.Amount++;
                _context.Basket.Update(goodInBasket);
                await _context.SaveChangesAsync();

                RedirectToAction("Goods", "Home");
            }
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: AynurZ/B4P
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                Users user = await _context.Users.FirstOrDefaultAsync(u => u.UserMail == model.Email);

                Users user2 = await _context.Users.FirstOrDefaultAsync(u => u.UserLogin == model.Login);

                if (user == null && user2 == null)
                {
                    // добавляем пользователя в бд
                    user = new Users {
                        UserMail = model.Email, UserPassword = model.Password, UserFamily = model.Family, UserName = model.Name, UserLogin = model.Login
                    };
                    Role userRole = await _context.Role.FirstOrDefaultAsync(r => r.RoleName == "user");

                    if (userRole != null)
                    {
                        user.Role = userRole;
                    }

                    _context.Users.Add(user);
                    await _context.SaveChangesAsync();

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

                    ViewData["Enter"] = "Личный";
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }