示例#1
0
        /// <summary>
        /// Invites the set of users specified in the invite request for the given community with the given role.
        /// </summary>
        /// <param name="inviteRequestItem">Invite request with details</param>
        /// <returns>Returns the collection of invite request send along with their tokens.</returns>
        public async Task<IEnumerable<InviteRequestItem>> InvitePeople(InviteRequestItem inviteRequestItem)
        {
            // Make sure inviteRequest is not null.
            this.CheckNotNull(() => new { inviteRequestItem });
            IList<InviteRequestItem> invitedPeople = new List<InviteRequestItem>();
            var userRole = _userRepository.GetUserRole(inviteRequestItem.InvitedByID, inviteRequestItem.CommunityID);
            if (userRole >= UserRole.Moderator)
            {
                var community =  _communityRepository.GetItem(c => c.CommunityID == inviteRequestItem.CommunityID && c.IsDeleted == false);

                this.CheckNotNull(() => new { community });

                // Create the invite request content.
                var inviteRequestContent = new InviteRequestContent();
                Mapper.Map(inviteRequestItem, inviteRequestContent);
                inviteRequestContent.InvitedDate = DateTime.UtcNow;

                foreach (var emailId in inviteRequestItem.EmailIdList)
                {
                    // For each user getting invited, add the invite request and associate it with the invite request content.
                    var inviteRequest = new InviteRequest();
                    inviteRequest.EmailID = emailId;
                    inviteRequest.InviteRequestToken = Guid.NewGuid();
                    inviteRequest.Used = false;
                    inviteRequest.IsDeleted = false;

                    inviteRequestContent.InviteRequest.Add(inviteRequest);

                    var invitedRequestItem = new InviteRequestItem();
                    Mapper.Map(inviteRequestItem, invitedRequestItem);
                    invitedRequestItem.EmailIdList.Add(emailId);
                    invitedRequestItem.InviteRequestToken = inviteRequest.InviteRequestToken;
                    invitedPeople.Add(invitedRequestItem);
                }

                // Add the invite request content to the community.
                community.InviteRequestContent.Add(inviteRequestContent);

                // Mark the community as updated.
                _communityRepository.Update(community);

                // Save all the changes made.
                _communityRepository.SaveChanges();
            }

            return invitedPeople;
        }
示例#2
0
        /// <summary>
        /// Gets the invite requests which are already sent for the given community and which are not yet used.
        /// </summary>
        /// <param name="userId">User who is reading the invite requests</param>
        /// <param name="communityId">Community for which invite requests are fetched</param>
        /// <param name="pageDetails">Page for which invite requests are fetched</param>
        /// <returns>List of open invite requests for the community</returns>
        public async Task<IEnumerable<InviteRequestItem>> GetInviteRequests(long userId, long communityId, PageDetails pageDetails)
        {
            this.CheckNotNull(() => new { pageDetails });

            IList<InviteRequestItem> inviteRequestItemList = new List<InviteRequestItem>();

            var userRole = _userRepository.GetUserRole(userId, communityId);
            if (userRole >= UserRole.Moderator)
            {
                // Condition to get all the pending requests irrespective of community.
                Expression<Func<InviteRequestsView, bool>> condition = (InviteRequestsView invite) => invite.Used == false && invite.CommunityID == communityId;
                Func<InviteRequestsView, object> orderBy = (InviteRequestsView invite) => invite.InvitedDate;

                // Gets the total items satisfying the condition
                pageDetails.TotalCount =   _inviteRequestsViewRepository.GetItemsCount(condition);
                pageDetails.TotalPages = (pageDetails.TotalCount / pageDetails.ItemsPerPage) + ((pageDetails.TotalCount % pageDetails.ItemsPerPage == 0) ? 0 : 1);

                foreach (var item in  _inviteRequestsViewRepository.GetItems(condition, orderBy, true, (pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage, pageDetails.ItemsPerPage))
                {
                    var inviteRequestItem = new InviteRequestItem();
                    Mapper.Map(item, inviteRequestItem);

                    inviteRequestItemList.Add(inviteRequestItem);
                }
            }

            return inviteRequestItemList;
        }