Esempio n. 1
0
        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
            }));
        }
Esempio n. 3
0
        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()));
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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));
            }
        }
Esempio n. 10
0
        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));
            }
        }
Esempio n. 12
0
        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));
            }
        }
Esempio n. 13
0
        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));
 }
Esempio n. 15
0
 public async Task <ActionResult <GetProfileDto> > Create(CreateProfileCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }
Esempio n. 16
0
        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);
 }
Esempio n. 18
0
 public ICommandHandler <CreateProfileCommand, int> Build(CreateProfileCommand command)
 {
     return(new CreateProfileCommandHandler(_service, command));
 }
Esempio n. 19
0
 public async Task <IActionResult> Create([FromBody] CreateProfileCommand input)
 {
     return(Ok(await _mediator.Send(input)));
 }
Esempio n. 20
0
 public void CreateProfile(CreateProfileCommand command)
 {
     _bus.SendCommand(command);
 }