public async Task <ActionResult <RequestDto> > CreateRequestSandBox([FromBody] RequestDto request, CancellationToken cancellationToken)
        {
            request.TrackingNumber = _hasher.CalculateTimeHash("TrackingNumber" + Guid.NewGuid());
            request.DateCreated    = DateTime.Now;
            var res = await ModelService.CreateByDtoAsync(request, cancellationToken);

            await _signaler.Signal(_userAccountService.GetAll(u => u.AgentUserAccount.Any(a => a.IsResponsible))
                                   .Select(u => u.Id).ToList(), nameof(Request), "A new request has arrived");

            return(res);
        }
        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));
        }
Ejemplo n.º 3
0
        // //[Authorize(Roles = UserGroups.Administrator + "," + UserGroups.RealEstateAdministrator)]
        public override async Task <ActionResult> Delete(int id, CancellationToken cancellationToken)
        {
            var user = await ModelService.GetAsync(u => u.Id == id, cancellationToken);

            if (user is null)
            {
                return(NoContent());
            }

            user.Email    = _fastHasher.CalculateTimeHash(user.Email);
            user.UserName = _fastHasher.CalculateTimeHash(user.UserName);
            user.IsActive = false;
            await ModelService.UpdateAsync(user, cancellationToken);

            return(NoContent());

            //return await base.Delete(id, cancellationToken);
        }