Esempio n. 1
0
        public async Task <IActionResult> Post([FromBody] UserPostRp resource)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._userComponent.CreateUser(resource);

            return(this.Created(Url.RouteUrl("GetUserId", new { id = response.Id }), response));
        }
Esempio n. 2
0
        public async Task <UserGetListRp> CreateUser(UserPostRp model)
        {
            var createdBy = this._identityGateway.GetIdentity();

            var entity = await this._dbContext.Users.Where(c => c.Email == model.Email).SingleOrDefaultAsync();

            if (entity == null)
            {
                entity = UserEntity.Factory.Create(createdBy, this._datetimeGateway.GetCurrentDateTime(), model.Email);
                this._dbContext.Users.Add(entity);
                await this._dbContext.SaveChangesAsync();
            }
            return(this._mapper.Map <UserGetListRp>(entity));
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateUser([FromBody] UserPostRp resource)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            await _userService.CreateUser(resource);

            if (DomainManager.HasConflicts())
            {
                return(this.Conflict(DomainManager.GetConflicts()));
            }

            return(this.Ok(new { UserId = await DomainManager.GetResult <string>("UserId") }));
        }
Esempio n. 4
0
        public async Task CreateUser(UserPostRp resource)
        {
            var user = new User {
                UserName = resource.Email, Email = resource.Email, FirstName = resource.GivenName, LastName = resource.Surname
            };
            var result = await _userManager.CreateAsync(user, resource.Password);

            if (!result.Succeeded)
            {
                await _domainManagerService.AddConflict(string.Join(", ", result.Errors));

                return;
            }

            await _userManager.AddClaimAsync(user, new Claim("givenname", resource.GivenName));

            await _userManager.AddClaimAsync(user, new Claim("fullname", $"{resource.GivenName} {resource.Surname}"));

            await _userManager.AddToRoleAsync(user, "agent");

            await _domainManagerService.AddResult("UserId", user.Id);
        }
Esempio n. 5
0
 public void given_information()
 {
     representation = Builder <UserPostRp> .CreateNew()
                      .With(x => x.Email = Faker.Internet.Email())
                      .Build();
 }