public async Task <ActionResult <ClientProfileDto> > CreateClientProfile(AddClientProfileDto dto)
        {
            try
            {
                var clientProfile = await clientManager.CreateClientProfileAsync(dto);

                return(CreatedAtAction("GetClientProfile", new { id = clientProfile.Id }, clientProfile));
            }
            catch (NotFoundException exc)
            {
                return(Problem(exc.Message, statusCode: StatusCodes.Status404NotFound));
            }
        }
Example #2
0
        public async Task <ClientProfileDto> CreateClientProfileAsync(AddClientProfileDto dto)
        {
            var clientProfile = mapper.Map <ClientProfile>(dto);

            var user1 = await identityService.GetUserAsync();

            await _context.Entry(user1).Reference(e => e.Profile).LoadAsync();

            if (dto.OrganizationId == null)
            {
                clientProfile.OrganizationId = user1.Profile.OrganizationId;
            }

            var entry = _context.ClientProfiles.Add(clientProfile);
            await _context.SaveChangesAsync();

            var user = new Models.User
            {
                Name      = clientProfile.FirstName,
                UserName  = clientProfile.Email,
                Email     = clientProfile.Email,
                ProfileId = entry.Entity.Id
            };

            var password = new Password(20).Next();

            var result = await _userManager.CreateAsync(user, password);

            await _userManager.AddToRoleAsync(user, RoleConstants.Client);

            //var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            //await emailSender.SendEmailAsync(
            //    user.Email,
            //    "ESSIQ Showroom - Please confirm your E-mail address",
            //    $"<a href=\"https://localhost:44386/user/confirm?email={user.Email}&token={token.Replace("=", "%3D")}\">Click here</a> to confirm your e-mail address.</a>");

            return(mapper.Map <ClientProfileDto>(clientProfile));
        }