public void AddUserForAssociate(User user, int associateId)
        {
            try
            {
                _context.Users.Add(user);

                _context.AssociateUsers.Add(new AssociateUser
                {
                    AssociateId = associateId,
                    UserId      = user.Id
                });
            }
            catch
            {
                User toRemove = _context.Users.SingleOrDefault(u => u.Id == user.Id);

                if (toRemove != null)
                {
                    _context.Users.Remove(toRemove);
                }

                throw;
            }

            _context.Users.Add(user);

            AssociateUser associateUser = new AssociateUser {
                AssociateId = associateId, UserId = user.Id
            };

            _context.AssociateUsers.Add(associateUser);
        }
Beispiel #2
0
        public Task <UserRM> GetUserForAssociate(int associateId, int userId)
        {
            ValidateAssociateExists(associateId);

            AssociateUser associateUser =
                _context.AssociateUsers.SingleOrDefault(au => au.AssociateId == associateId && au.UserId == userId);

            if (associateUser == null)
            {
                throw new InvalidOperationException("User not found for associate.");
            }

            return(GetUser(userId));
        }
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            var user = new AssociateUser {
                UserName = model.Email
            };
            IdentityResult result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }