public async Task <IActionResult> GetById(string id)
        {
            var userId = JWTAttributesService.GetSubject(Request);
            var org    = await _orgRepository.FindById(id);

            var keyContactList = await _keyContactRepo.FindByOrgId(id);

            return(Ok(org));
        }
Exemple #2
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());
        }
Exemple #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());
        }