Exemplo n.º 1
0
        public async Task <Unit> Handle(InitReviewerCommand request, CancellationToken cancellationToken)
        {
            var user       = _identitySvc.GetUser();
            var userFromDb = await _reviewerRepo.Find(user.Id);

            if (userFromDb == null)
            {
                userFromDb = new ReviewerInfo
                {
                    Id                = user.Id,
                    EmpId             = user.EmployeeId,
                    FirstName         = user.FirstName,
                    LastName          = user.LastName,
                    LastLoginDateTime = user.LoginTime,
                    LoginName         = user.UserName
                };
                _reviewerRepo.Add(userFromDb);
            }
            else
            {
                userFromDb.Id                = user.Id;
                userFromDb.EmpId             = user.EmployeeId;
                userFromDb.FirstName         = user.FirstName;
                userFromDb.LastName          = user.LastName;
                userFromDb.LastLoginDateTime = user.LoginTime;
                userFromDb.LoginName         = user.UserName;
            }
            await _uow.SaveEntitiesAsync();

            return(Unit.Value);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var test = await _reviewerRepository.GetByNicknameAsync(model.Nickname);

                if (test == null)
                {
                    User user = new User
                    {
                        Email    = model.Email,
                        UserName = model.Email
                    };

                    var result = await _userManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        await _userManager.AddToRoleAsync(user, "User");

                        Reviewer reviewer = new Reviewer
                        {
                            UserId   = user.Id,
                            Nickname = model.Nickname,
                            Age      = model.Age
                        };

                        _reviewerRepository.Add(reviewer);
                        await _reviewerRepository.SaveChangesAsync();

                        await _signInManager.SignInAsync(user, false);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error.Description);
                        }
                    }
                }

                ModelState.AddModelError("", "Цей нікнейм вже зайнято!");
            }

            return(View(model));
        }
Exemplo n.º 3
0
 public async Task AddAndSave(Reviewer reviewer)
 {
     _reviewerRepo.Add(reviewer);
     await _reviewerRepo.Save();
 }