public async Task <ActionResult> UpdateAgent([FromBody] AgentAccountDto dto, CancellationToken cancellationToken)
        {
            var user = await _userAccountService.GetAsync(u => u.Id == dto.UserId, cancellationToken);

            user.FirstName = dto.FirstName;
            user.LastName  = dto.LastName;
            if (dto.UpdatePassword)
            {
                user.PasswordHash = _passwordService.HashUserPassword(dto.Email, dto.Password);
            }
            user.Address01  = dto.Address01;
            user.Address02  = dto.Address02;
            user.Phone01    = dto.Phone01;
            user.Phone02    = dto.Phone02;
            user.MiddleName = dto.MiddleName;
            user.ZipCode    = dto.ZipCode;

            await _userAccountService.UpdateAsync(user, cancellationToken);

            var agent = await ModelService.GetAsync(a => a.Id == dto.AgentId, cancellationToken);

            agent.Description = dto.Description;
            agent.HasPublishingAuthorization = dto.HasPublishingAuthorization;
            agent.IsResponsible = dto.IsResponsible;

            await ModelService.UpdateAsync(agent, cancellationToken);

            return(NoContent());
        }
示例#2
0
        public Task <AgentAccountDto> Update(AgentAccountDto agentAccountDto)
        {
            AgentAccount agentAccount = ObjectMapper.Map <AgentAccount>(agentAccountDto);

            agentAccount = _agentAccountRepository.Update(agentAccount);
            return(Task.FromResult <AgentAccountDto>(agentAccountDto));
        }
示例#3
0
        public async Task <AgentAccountDto> GetById(int id)
        {
            AgentAccount result = await _agentAccountRepository.GetAsync(id);

            AgentAccountDto dto = ObjectMapper.Map <AgentAccountDto>(result);

            return(dto);
        }
        public async Task <ActionResult <AgentAccountDto> > CreateAgent([FromBody] AgentAccountDto dto, CancellationToken cancellationToken)
        {
            if (_userProvider.RealEstateId is null)
            {
                throw new AppException("you cannot create new agent please try again later");
            }
            var dupUser = await _userAccountService.GetAsync(u => u.Email == dto.Email || u.UserName == dto.UserName,
                                                             cancellationToken);

            if (dupUser != null)
            {
                if (dupUser.Email == dto.Email)
                {
                    throw new AppException("There is another user registered with this email address. Please chose another one.");
                }
                if (dupUser.UserName == dto.UserName)
                {
                    throw new AppException("There is another user registered with this username. Please chose another one.");
                }
            }

            var passwordHash = _passwordService.HashUserPassword(dto.Email, dto.Password);
            var user         = await _userAccountService.CreateAsync(new UserAccount
            {
                ActivationKey             = _fastHasher.CalculateHash(dto.FirstName + dto.LastName + dto.Email + dto.UserName),
                Email                     = dto.Email,
                UserName                  = dto.UserName,
                FirstName                 = dto.FirstName,
                LastName                  = dto.LastName,
                HasExternalAuthentication = false,
                IsConfirmed               = false,
                PasswordHash              = passwordHash,
                RegistrationDate          = DateTime.Now,
                Address01                 = dto.Address01,
                Address02                 = dto.Address02,
                Phone01                   = dto.Phone01,
                Phone02                   = dto.Phone02,
                IsActive                  = true,
                MiddleName                = dto.MiddleName,
                ReferralCode              = _fastHasher.CalculateTimeHash(dto.Email),
                ZipCode                   = dto.ZipCode,
            }, cancellationToken);

            dto.UserId = user.Id;

            var agent = await ModelService.CreateAsync(new Agent
            {
                Description = dto.Description,
                HasPublishingAuthorization = dto.HasPublishingAuthorization,
                IsResponsible = dto.IsResponsible,
                RealEstateId  = _userProvider.RealEstateId.Value,
                MetadataJson  = "{}",
                UserAccountId = user.Id,
            }, cancellationToken);

            dto.AgentId = agent.Id;
            return(CreatedAtAction(nameof(CreateAgent), dto));
        }
示例#5
0
        public Task <AgentAccountDto> Create(AgentAccountDto agentAccountDto)
        {
            agentAccountDto.CreatorUserId = AbpSession.UserId.Value;
            agentAccountDto.CreationTime  = DateTime.Now;
            AgentAccount agentAccount = ObjectMapper.Map <AgentAccount>(agentAccountDto);

            agentAccountDto.Id = _agentAccountRepository.InsertAndGetId(agentAccount);
            return(Task.FromResult <AgentAccountDto>(agentAccountDto));
        }