예제 #1
0
        public async Task <IActionResult> InviteUser(InviteViewModel inviteViewModel)
        {
            Invite invite = new Invite();

            invite.Email          = inviteViewModel.Email;
            invite.FacilityId     = inviteViewModel.FacilityId;
            invite.OrganizationId = inviteViewModel.organization_id;
            invite.RoleId         = inviteViewModel.RoleId;
            invite.CreationDate   = DateTime.Now;
            var InvitedUser = await _inviteservice.InsertInvite(invite);

            var claimsIdentity = new ClaimsIdentity(new List <Claim>()
            {
                new Claim(ClaimTypes.Name, InvitedUser.Email),
                new Claim(ClaimTypes.NameIdentifier, InvitedUser.Id.ToString()),
            }, "Identity.Application");

            var token = _passwordService.CreateAccessToken(_passwordService.CreateJwtClaims(claimsIdentity));

            var baseUrl = string.Format("{0}://{1}{2}/", Request.Scheme, Request.Host, Request.PathBase) + "api/User/GetInvitedUser?token=" + token;
            //api / User / GetInvitedUser ? id = 4
            var organisation = await _organizationService.GetOrganization(inviteViewModel.organization_id);

            var emailBody     = string.Format(AppConstants.InviteEmailTemplate, baseUrl);
            var emailsubjects = string.Format(AppConstants.InviteEmailSubject, organisation.Name);
            var apiKey        = AppConstants.SendGridKey;
            var result        = await _sendEmailService.send_email_sendgrid(apiKey, invite.Email, emailsubjects, emailBody);

            return(Ok(result));
        }
예제 #2
0
        public async Task <IActionResult> SendInvite(InviteDto inviteDto)
        {
            //Not able to send invite. Followed by errors.
            var invite = _mapper.Map <Invite>(inviteDto);

            await _inviteService.InsertInvite(invite, User);

            //SEND EMAIL
            inviteDto = _mapper.Map <InviteDto>(invite);

            var response = new ApiResponse <InviteDto>(inviteDto);

            return(Ok(response));
        }