Example #1
0
        public async Task <IActionResult> AddPartnerUser(Guid partnerId, Guid userId)
        {
            // Make sure the person adding the user is either an admin or already a user for the partner
            var currentUser = await userRepository.GetUserByNameIdentifier(User.FindFirst(ClaimTypes.NameIdentifier).Value).ConfigureAwait(false);

            if (!currentUser.IsSiteAdmin)
            {
                var currentUserPartner = partnerUserRepository.GetPartnerUsers().FirstOrDefault(pu => pu.PartnerId == partnerId && pu.UserId == currentUser.Id);

                if (currentUserPartner == null)
                {
                    return(Forbid());
                }
            }

            var partnerUser = new PartnerUser()
            {
                PartnerId           = partnerId,
                UserId              = userId,
                CreatedByUserId     = currentUser.Id,
                LastUpdatedByUserId = currentUser.Id
            };

            await partnerUserRepository.AddPartnerUser(partnerUser).ConfigureAwait(false);

            return(CreatedAtAction(nameof(GetPartnerUser), new { partnerId, userId }));
        }
Example #2
0
        public async Task CreatePartner(PartnerRequest partnerRequest)
        {
            // Convert the partner request to a new partner
            var partner = partnerRequest.ToPartner();

            // Add the partner record
            var newPartner = await partnerRepository.AddPartner(partner).ConfigureAwait(false);

            // Make the creator of the partner request a registered user for the partner
            var partnerUser = new PartnerUser
            {
                PartnerId           = newPartner.Id,
                UserId              = partnerRequest.CreatedByUserId,
                CreatedByUserId     = partnerRequest.CreatedByUserId,
                LastUpdatedByUserId = partnerRequest.LastUpdatedByUserId,
            };

            await partnerUserRepository.AddPartnerUser(partnerUser).ConfigureAwait(false);

            // Notify user when their request has been approved and what to do next
            // Need a template for this
            //var email = new Email
            //{
            //    Message = $"From Email: {partnerRequest.PrimaryEmail}\nFrom Name:{partnerRequest.Name}\nMessage:\n{partnerRequest.Notes}",
            //    Subject = "Partner Request"
            //};
            //email.Addresses.Add(new EmailAddress { Name = Constants.TrashMobEmailName, Email = Constants.TrashMobEmailAddress });

            //await emailManager.SendSystemEmail(email, CancellationToken.None).ConfigureAwait(false);
        }