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)); }
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)); }
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") })); }
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); }
public void given_information() { representation = Builder <UserPostRp> .CreateNew() .With(x => x.Email = Faker.Internet.Email()) .Build(); }