Beispiel #1
0
 public async Task SendOrgApprovedEmail(EmailAddress from, EmailAddress to, string orgName, string orgId)
 {
     var templateParameters = new TemplateParameters
     {
         OpenReferralAppUrl = _settings.BaseAddress + $"manage-organisation/{orgId}",
         OrganisationName   = orgName,
         UserName           = JWTAttributesService.GetEmail(_httpContextAccessor.HttpContext.Request),
     };
     var client   = new SendGridClient(_apiKey);
     var msg      = MailHelper.CreateSingleTemplateEmail(from, to, _settings.OrgApprovedTemplate, templateParameters);
     var response = await client.SendEmailAsync(msg);
 }
        public async Task <IActionResult> Post([FromBody] PendingOrganisation organisation, [FromServices] IOptions <ApiBehaviorOptions> apiBehaviorOptions)
        {
            var currentOrgs = _orgRepository.GetAll();
            var pendingOrgs = _pendingOrgRepository.GetAll();

            try
            {
                Guid.Parse(organisation.Id);
            }
            catch (Exception _)
            {
                ModelState.AddModelError(nameof(Organisation.Id), "Organization Id is not a valid Guid");
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }
            if (organisation.CharityNumber > 0 &&
                (currentOrgs.Any(org => org.CharityNumber == organisation.CharityNumber) ||
                 pendingOrgs.Any(org => org.CharityNumber == organisation.CharityNumber)))
            {
                ModelState.AddModelError(nameof(Organisation.CharityNumber), "Charity number already exists.");
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }
            if (currentOrgs.Any(org => org.Name == organisation.Name) || pendingOrgs.Any(org => org.Name == organisation.Name))
            {
                ModelState.AddModelError(nameof(Organisation.Name), "Organisation name already exists.");
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }
            else
            {
                organisation.UserId    = JWTAttributesService.GetSubject(Request);
                organisation.UserEmail = JWTAttributesService.GetEmail(Request);
                await _pendingOrgRepository.InsertOne(organisation);

                await _sendgridSender.SendOrgRequestEmail(
                    new SendGrid.Helpers.Mail.EmailAddress("*****@*****.**"),
                    new SendGrid.Helpers.Mail.EmailAddress(_configuration["Admin:EmailAddress"]),
                    organisation.Name
                    );

                return(Accepted(organisation));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> CreateRequest([FromRoute] string orgId)
        {
            // Restricts the requests so you only get one request per org per user ID
            var userId = JWTAttributesService.GetSubject(Request);
            var email  = JWTAttributesService.GetEmail(Request);
            var existingRequestsForUser = _orgMemberRepository.GetRequestsAboutUser(userId).Where(x => x.OrgId == orgId);

            if (existingRequestsForUser.Count() == 0)
            {
                var orgmemberRequest = new OrganisationMember()
                {
                    Id = Guid.NewGuid().ToString(), OrgId = orgId, Status = OrganisationMembersStatus.REQUESTED, UserId = userId, Email = email
                };
                await _orgMemberRepository.InsertOne(orgmemberRequest);
            }
            else
            {
                var request = existingRequestsForUser.First();
                request.Status = OrganisationMembersStatus.REQUESTED;
                await _orgMemberRepository.UpdateOne(request);
            }

            // Get Key Contact for org
            var keyContacts = await _keyContactRepo.FindApprovedByOrgId(orgId);

            var org = await _orgRepository.FindById(orgId);

            foreach (var kc in keyContacts)
            {
                await _sendgridSender.SendSingleTemplateEmail(
                    new SendGrid.Helpers.Mail.EmailAddress("*****@*****.**"),
                    new SendGrid.Helpers.Mail.EmailAddress(kc.UserEmail),
                    org.Name
                    );
            }

            return(Ok());
        }
Beispiel #4
0
        public async Task <IActionResult> AddAdminRequestToKeyContact([FromRoute] string orgId)
        {
            await _keyContactRepository.InsertOne(new KeyContacts()
            {
                Id = Guid.NewGuid().ToString(), OrgId = orgId, UserId = JWTAttributesService.GetSubject(Request), UserEmail = JWTAttributesService.GetEmail(Request), IsAdmin = true, IsPending = true
            });

            var keyContacts = await _keyContactRepository.FindApprovedByOrgId(orgId);

            var org = await _organisationRepository.FindById(orgId);

            foreach (var kc in keyContacts)
            {
                await _sendgridSender.SendSingleTemplateEmail(
                    new SendGrid.Helpers.Mail.EmailAddress("*****@*****.**"),
                    new SendGrid.Helpers.Mail.EmailAddress(kc.UserEmail),
                    org.Name
                    );
            }
            return(Ok());
        }
Beispiel #5
0
        public async Task <IActionResult> AddKeyContact([FromRoute] string orgId)
        {
            await _keyContactRepository.InsertOne(new KeyContacts()
            {
                Id = Guid.NewGuid().ToString(), OrgId = orgId, UserId = JWTAttributesService.GetSubject(Request), UserEmail = JWTAttributesService.GetEmail(Request)
            });

            return(Ok());
        }