public async Task <(Result Result, string UserId)> CreateUserAsync(string userName, string firstName, string lastName, string password) { var user = new ApplicationUser { UserName = userName, Email = userName, }; var result = await _userManager.CreateAsync(user, password); if (!result.Succeeded) { return(result.ToApplicationResult(), user.Id); } await _userManager.AddClaimAsync(user, new Claim("identifier", user.Id)); var command = new CreateProfileCommand { FirstName = firstName, LastName = lastName, UserId = user.Id }; await _mediator.Send(command); return(result.ToApplicationResult(), user.Id); }
public override Task <CreateProfile.Types.Response> CreateProfile(CreateProfile.Types.Request request, ServerCallContext context) { var model = new CreateProfileCommand { TransactionId = request.TransactionId, OrganizationUserId = request.OrganizationUserId, OrganizationId = request.OrganizationId, ProfileValues = request.ProfileValuesListView?.Select(pv => new ProfileValueCreateModel { Value = pv.Value, ProfileParameterId = pv.ProfileParameterId.Value, TransactionId = pv.TransactionId }).ToList() }; var result = this.profileService.CreateProfile(model); if (result.IsFailure) { HandleResultFailure(context, result); return(null); } return(Task.FromResult(new CreateProfile.Types.Response { ProfileId = result.Value })); }
public ActionResult <int> Post([FromBody] CreateProfileDTO request) { var command = new CreateProfileCommand(_mapper.Map <Data.Models.Profile>(request)); var handler = _commandHandler.Build(command); return(Ok(handler.Execute())); }
public Result <int> CreateProfile(CreateProfileCommand command) { if (profileRepository.ProfileExistsForOrganizationUser(command.OrganizationUserId, command.OrganizationId)) { return(new Result <int>(ProfileServiceErrors.ProfileForOrganizationUserAlreadyExists())); } // TODO - think about the wanted strategy for empty/optional profile values /*if (ValidateProfileValue(command.ProfileValues)) * { * return new Result<int>(ProfileServiceErrors.InvalidProfileValuesData()); * }*/ if (!organizationUserRepository.OrganizationUserExists(command.OrganizationUserId, command.OrganizationId)) { return(new Result <int>(ProfileServiceErrors.InvalidOrganizationUserId())); } var(invalidProfileParametersFound, invalidProfileParametersCollection) = ValidateProfileParameters(command.ProfileValues.ToList <IProfileValueModel>()); if (invalidProfileParametersFound) { return(new Result <int>(invalidProfileParametersCollection)); } var profileId = profileRepository.CreateProfile(command); return(new Result <int>(profileId)); }
public async Task <(Result Result, string UserId)> CreateExternalLoginUserAsync(string email, string firstName, string lastName) { var user = await _userManager.FindByEmailAsync(email); if (user == null) { user = new ApplicationUser { UserName = email, Email = email, EmailConfirmed = true }; var result = await _userManager.CreateAsync(user); if (!result.Succeeded) { return(result.ToApplicationResult(), user.Id); } var command = new CreateProfileCommand { FirstName = firstName, LastName = lastName, UserId = user.Id }; await _mediator.Send(command); return(result.ToApplicationResult(), user.Id); } throw new NotFoundException(); }
public async Task <CommandResult> Handler(CreateProfileCommand command) { if (!command.Validated()) { return(new CommandResult(false, "Error editing profile", command.Notifications)); } var user = await _userRepository.GetUserById(new Guid(command.UserId)); if (user == null) { return(new CommandResult(false, "User not found.", null)); } var address = new Address(command.Street, command.City, command.Country, command.ZipCode); var email = new Email(command.Email); var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Cpf, command.Cnpj); var phone = new Phone(command.FixPhone, command.MobilePhone); await _addressRepository.Save(address); var imageUrl = ""; var image = command.Image; if (command.Image != null && command.Image.Length > 0) { imageUrl = await _uploadService.UploadImageProfile(user.Id, image.OpenReadStream()); } var profile = new Profile(name, imageUrl, document, email, phone, user, address); await _profileRepository.Save(profile); var response = new ProfileCommandResponse( profile.Id, profile.Document.Cpf, profile.Document.Cnpj, profile.Email.Address, profile.Name.FirstName, profile.Name.LastName, profile.Phone.FixNumber, profile.Phone.MobileNumber, profile.ImageUrl, profile.User.Id, profile.Address.Id, profile.Address.Street, profile.Address.City, profile.Address.Country, profile.Address.ZipCode ); return(new CommandResult(true, "Profile created.", response)); }
private void SaveCommandExecuted() { var command = new CreateProfileCommand { Profile = _profile, Account = _account, Password = _password }; try { _createProfileHandler.Execute(command); CancelCommandExecuted(); } catch (Exception ex) { //Log.Error(ex.Message, ex); } }
public async Task CreateProfileCommandTestAsync(string identityUserId, CreateProfileResponse result) { CreateProfileCommand request = new CreateProfileCommand { IdentityUserId = identityUserId, }; CreateProfileCommandHandler handler = new CreateProfileCommandHandler(_createFixture.Context); var expectedResult = await handler.Handle(request, new CancellationToken()); Assert.Equal(expectedResult.IsSuccessful, result.IsSuccessful); if (result.IsSuccessful) { Profile profile = _createFixture.Context.Profiles.Find(expectedResult.Id); Assert.Equal(profile?.IdentityUserId, identityUserId); } Assert.Equal(expectedResult.Message, result.Message); }
public async Task <IActionResult> Create([FromBody] CreateProfileCommand command) { try { if (!ModelState.IsValid) { return(base.BadRequest(ModelState)); } var result = await _mediator.Send <CreateProfileCommandResult>(command); return(base.Created($"api/Profiles/{result.Payload.Id}", result)); } catch (InvalidOperationException ex) { return(base.Conflict(ex.Message)); } }
public int CreateProfile(CreateProfileCommand command) { var profile = new ProfileEntity { OrganizationId = command.OrganizationId, OrganizationUserId = command.OrganizationUserId, TransactionId = command.TransactionId, ProfileValues = mapper.Map <List <ProfileValueEntity> >(command.ProfileValues) }; using (var transaction = this.context.Database.BeginTransaction()) { this.context.Profiles.Add(profile); this.context.SaveChanges(); transaction.Commit(); } return(profile.ProfileEntityId); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = null)] HttpRequest req, ILogger log, CancellationToken cancellationToken) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <CreateProfileRequest>(requestBody); var command = new CreateProfileCommand(data.DeviceId, data.PushToken, data.PhoneNumber, data.Locale, data.Latitude, data.Longitude, data.Accuracy); try { var result = await mediator.Send(command, cancellationToken); return(new OkObjectResult(result)); } catch (DomainException ex) { var errors = validation.ProcessErrors(ex); return(new BadRequestObjectResult(errors)); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "profile")] HttpRequest req, ILogger log, CancellationToken cancellationToken) { try { var clientInfo = clientInfoService.Parse(req.Headers["User-Agent"]); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <CreateProfileRequest>(requestBody); var command = new CreateProfileCommand(data.DeviceId, data.PushToken, data.Locale, clientInfo.Name, clientInfo.Integrator, clientInfo.Version, clientInfo.OperationSystem); var result = await mediator.Send(command, cancellationToken); return(new OkObjectResult(result)); } catch (DomainException ex) { var errors = validation.ProcessErrors(ex); return(new BadRequestObjectResult(errors)); } }
public async Task <IActionResult> CreateProfile([FromForm] CreateProfileCommand command) { var response = await _handler.Handler(command); return(response.Success ? StatusCode(201, response) : StatusCode(400, response)); }
public async Task <GetProfileDto> CreateProfile(CreateProfileCommand profileCommand) { return(await _mediator.Send(profileCommand)); }
public async Task <ActionResult <GetProfileDto> > Create(CreateProfileCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task <IActionResult> CreateProfile([FromBody, Required] CreateProfileCommand profile) { var commandResult = await _mediator.Send(profile); return(CreatedAtAction(nameof(GetProfileById), new { profileId = commandResult.ProfileId }, commandResult)); }
public CreateProfileViewModel() { CreateProfileCommand = new CreateProfileCommand(CreateProfile); }
public ICommandHandler <CreateProfileCommand, int> Build(CreateProfileCommand command) { return(new CreateProfileCommandHandler(_service, command)); }
public async Task <IActionResult> Create([FromBody] CreateProfileCommand input) { return(Ok(await _mediator.Send(input))); }
public void CreateProfile(CreateProfileCommand command) { _bus.SendCommand(command); }