Пример #1
0
        public async Task<IActionResult> Post([FromBody]RegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var userIdentity = Mapper.Map<IdentityUser>(model);
            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded) throw new NotImplementedException();
            if (model.IsAdmin)
            {
                var customer = new DataAccess.IdentityEntities.Customer()
                {
                    IdentityId = userIdentity.Id,
                    Naam = model.UserName
                };
                await _customerWriter.Add(new DataAccess.BMEntities.Customer() { Name = model.UserName });
                await _identityContext.AddAsync(customer);
            }
            else
            {
                var admin = new Admin()
                {
                    IdentityId = userIdentity.Id,
                };
                await _identityContext.AddAsync(admin);
            }
            await _identityContext.SaveChangesAsync();

            return new OkResult();
        }
        public async Task Register(string route, int?organisationId)
        {
            if (_context.SrnAuthAssignments.Any(a => a.Route == route && a.OrganisationId == organisationId))
            {
                throw new Exception("The authorisation assignment already exists.");
            }

            await _context.AddAsync(new SrnAuthAssignment { Route = route, OrganisationId = organisationId });

            await _context.SaveChangesAsync();
        }
Пример #3
0
        public async Task AddAsync(Token token, int userId)
        {
            var user = await _identityRepository.GetAsync(userId);

            if (user == null)
            {
                throw new RepositoryException("TokenRepository: not found user.");
            }

            token.User = user;
            await _context.AddAsync(token);

            await _context.SaveChangesAsync();
        }
Пример #4
0
        public async Task <IdentityResult> CreateAsync(User user, CancellationToken cancellationToken)
        {
            await _identityContext.AddAsync(user, cancellationToken);

            return(IdentityResult.Success);
        }
Пример #5
0
 Task IUserRepository.AddAsync(User user) => db.AddAsync(user);