示例#1
0
        public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
        {
            var user = await _userReadRepository.GetAsync(request.Id);

            var UserEmailVerify = await _userReadRepository.GetByEmailAsync(request.Email);

            if (user.Id != UserEmailVerify.Id)
            {
                return(new Response().AddError("Email already registered"));
            }

            user.Update(request.Name, request.Email);
            _userWriteRepository.Update(user);
            await _uow.CommitAsync();

            var emailSubject = "Alteração de conta";

            var emailBody = $"<p>Olá, {user.Name}!</p>" +
                            "<p>Sua conta de usuário no sistema Calculador de Dívida alterada com sucesso!<p/>";

            List <string> emails = new List <string>();

            emails.Add(user.Email);

            await _mediator.Publish(new Notification(emailSubject, emailBody, emails));

            return(new Response(user));
        }
示例#2
0
            public async Task HandleAsync(ChangePasswordCommand command)
            {
                var customerDomain = _mapper.Map <Customer>(command.ComandData);
                var customer       = await _customerReadRepository.Get(command.ComandData.TenantId);

                if (customer == null)
                {
                    await _customerWriteRepository.Add(customerDomain);
                }

                var user = await _userReadRepository.GetByUsername(command.ComandData.Data.Username);

                var userDomain = new User
                {
                    Id = user == null?Guid.NewGuid() : user.Id,
                             CustomerId = command.ComandData.TenantId,
                             Username   = command.ComandData.Data.Username,
                             RoleId     = (int)Common.Enums.Roles.Local,
                             Password   = MD5.CreateMD5(command.ComandData.Data.Password)
                };

                if (user == null)
                {
                    await _userWriteRepository.Add(userDomain);
                }
                else
                {
                    await _userWriteRepository.Update(userDomain);
                }
            }
        public async Task <EntityResult <Domain.Models.Entity.User> > Update(UpdateUserCommand command)
        {
            var result =
                Domain.Models.Entity.User.TryCreateToUpdate(command.Id, command.Name, command.Email, command.Password);

            if (result.Valid)
            {
                await _userWriteRepository.Update(result.Entity);
            }

            return(result);
        }
        public async Task Handle(UpdateUserCommand message)
        {
            var existingUser = await userReadRepository.GetById(message.Id);

            if (existingUser == null)
            {
                throw new Exception("User not exists.");
            }
            ;

            if (await userReadRepository.ExistUserByEmail(message.Id, message.Email))
            {
                throw new Exception("User already exists with this email.");
            }

            await userWriteRepository.Update(
                Models.User.CreateToUpdate(message.Id, message.Name, message.Email, existingUser.Password)
                );
        }
示例#5
0
        public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
        {
            var user = await _userReadRepository.GetAsync(request.Id);

            user.TurnIntoAdmin();

            _userWriteRepository.Update(user);
            await _uow.CommitAsync();

            var emailSubject = "Você é um administrador";

            var emailBody = $"<p>Olá, {user.Name}!</p>" +
                            "<p>Sua conta no sistema Calculador de Dívida agora é um administrador!.<p/>";

            List <string> emails = new List <string>();

            emails.Add(user.Email);

            await _mediator.Publish(new Notification(emailSubject, emailBody, emails));

            return(new Response(user));
        }