예제 #1
0
        public async Task <IActionResult> SignUp(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                Accounts user = await _context.Accounts.FirstOrDefaultAsync(u => u.Login == model.Login);

                if (user == null)
                {
                    Guid     Id = Guid.NewGuid();
                    Accounts us = new Accounts()
                    {
                        Id           = Id.ToString(),
                        Login        = model.Login,
                        Password     = model.Password,
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        MiddleName   = model.MiddleName,
                        GenderId     = model.GenderId,
                        RoleId       = model.RoleId,
                        BirthDate    = model.BirthDate,
                        RangId       = 1,
                        RagisterDate = DateTime.Now.Date
                    };
                    await _context.Accounts.AddAsync(us);

                    await _context.SaveChangesAsync();
                    await Authenticate(us);

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