public void EnrollTo(Int32 idCommunity, String name, String path, lm.Comol.Core.BaseModules.CommunityManagement.dtoCommunitiesFilters filters)
        {
            Int32 idPerson = UserContext.CurrentUserID;

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                Boolean reloadCommunities          = false;
                ModuleDashboard.ActionType dAction = ModuleDashboard.ActionType.None;
                dtoCommunityInfoForEnroll  item    = Service.GetEnrollingItem(idPerson, idCommunity, path);
                litePerson person = CurrentManager.GetLitePerson(idPerson);
                if (item != null && item.Id > 0 && person != null && person.Id > 0)
                {
                    if (!item.AllowEnroll)
                    {
                        dAction = ModuleDashboard.ActionType.EnrollNotAllowed;
                        View.DisplayEnrollMessage(item, dAction);
                    }
                    else
                    {
                        if (!item.HasConstraints && item.AllowUnsubscribe)
                        {
                            dtoEnrollment enrollment = Service.EnrollTo(idPerson, item);
                            if (enrollment == null)
                            {
                                dAction = ModuleDashboard.ActionType.UnableToEnroll;
                                View.DisplayEnrollMessage(item, dAction);
                            }
                            else
                            {
                                View.DisplayEnrollMessage(enrollment, enrollment.IdCommunity, person, Service.GetTranslatedProfileType(person), CurrentManager.GetUserDefaultOrganizationName(idPerson));
                                reloadCommunities = true;
                                dAction           = (enrollment.Status == EnrolledStatus.NeedConfirm) ? ModuleDashboard.ActionType.EnrollToCommunityWaitingConfirm : ModuleDashboard.ActionType.EnrollToCommunity;
                                lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.BaseModules.CommunityManagement.Domain.CacheKeys.UserCommunitiesTree(idPerson));
                            }
                        }
                        else
                        {
                            dAction = ModuleDashboard.ActionType.RequireEnrollConfirm;
                            View.DisplayConfirmMessage(item);
                        }
                    }
                }
                else
                {
                    dAction = ModuleDashboard.ActionType.UnableToEnroll;
                    View.DisplayUnknownCommunity(name);
                }
                View.SendUserAction(0, CurrentIdModule, idCommunity, dAction);
                if (reloadCommunities)
                {
                    LoadTree(filters, View.AdvancedMode, View.ReferenceIdCommunity, false);
                }
            }
        }
        public void EnrollTo(dtoCommunityInfoForEnroll community, lm.Comol.Core.BaseModules.CommunityManagement.dtoCommunitiesFilters filters, Boolean advancedMode, Int32 idReferenceCommunity)
        {
            Int32 idPerson = UserContext.CurrentUserID;

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                Boolean reloadCommunities = false;
                if (community != null)
                {
                    reloadCommunities = true;
                    litePerson person           = CurrentManager.GetLitePerson(idPerson);
                    String     profileType      = Service.GetTranslatedProfileType(person);
                    String     organizationName = CurrentManager.GetUserDefaultOrganizationName(idPerson);

                    dtoEnrollment enrollment = Service.EnrollTo(idPerson, community);
                    if (enrollment != null)
                    {
                        switch (enrollment.Status)
                        {
                        case EnrolledStatus.Available:
                        case EnrolledStatus.NeedConfirm:
                            lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.BaseModules.CommunityManagement.Domain.CacheKeys.UserCommunitiesTree(idPerson));
                            //View.NotifyEnrollment(enrollment, person, profileType, organizationName);

                            View.SendUserAction(0, CurrentIdModule, community.Id, (enrollment.Status == EnrolledStatus.Available) ? ModuleDashboard.ActionType.EnrollToCommunity : ModuleDashboard.ActionType.EnrollToCommunityWaitingConfirm);
                            reloadCommunities = true;
                            break;
                        }
                        View.DisplayEnrollMessage(enrollment, enrollment.IdCommunity, person, Service.GetTranslatedProfileType(person), CurrentManager.GetUserDefaultOrganizationName(idPerson));
                    }
                    if (reloadCommunities)
                    {
                        LoadTree(filters, advancedMode, idReferenceCommunity, false);
                    }
                }
                else
                {
                    View.SendUserAction(0, CurrentIdModule, ModuleDashboard.ActionType.NoSelectedCommunitiesToEnroll);
                }
            }
        }
        public void EnrollTo(List <dtoCommunityToEnroll> sCommunities, Boolean applyToAll, Int32 itemsForPage, RangeSettings range, lm.Comol.Core.BaseModules.CommunityManagement.dtoCommunitiesFilters filters, OrderItemsToSubscribeBy orderBy, Boolean ascending, Int32 pageIndex)
        {
            Int32 idPerson = UserContext.CurrentUserID;

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                ModuleDashboard.ActionType dAction = ModuleDashboard.ActionType.None;
                Boolean reloadCommunities          = false;

                List <dtoCommunityToEnroll> cCommunities = View.CurrentSelectedItems;
                if (sCommunities.Where(i => !i.Selected).Any())
                {
                    cCommunities = cCommunities.Where(c => !sCommunities.Where(s => s.Id == c.Id).Any() || sCommunities.Where(s => s.Selected && s.Id == c.Id).Any()).ToList();
                }
                if (sCommunities.Where(i => i.Selected).Any())
                {
                    List <Int32> idCommunities = cCommunities.Select(c => c.Id).ToList();
                    cCommunities.AddRange(sCommunities.Where(s => s.Selected && !idCommunities.Contains(s.Id)).ToList());
                }

                List <dtoCommunityInfoForEnroll> items = Service.GetEnrollingItems(idPerson, cCommunities);
                if (items != null && items.Where(i => i.Id > 0).Any())
                {
                    if (!items.Where(i => i.AllowEnroll).Any())
                    {
                        dAction = ModuleDashboard.ActionType.EnrollNotAllowed;
                        if (items.Count == 1)
                        {
                            View.DisplayEnrollMessage(items.FirstOrDefault(), dAction);
                        }
                        else
                        {
                            View.DisplayEnrollMessage(items.Count, dAction);
                        }
                    }
                    else
                    {
                        reloadCommunities = true;
                        litePerson           person           = CurrentManager.GetLitePerson(idPerson);
                        String               profileType      = Service.GetTranslatedProfileType(person);
                        String               organizationName = CurrentManager.GetUserDefaultOrganizationName(idPerson);
                        List <dtoEnrollment> enrollments      = new List <dtoEnrollment>();
                        foreach (dtoCommunityInfoForEnroll cm in items.Where(i => i.AllowEnroll && !i.HasConstraints))
                        {
                            dtoEnrollment enrollment = Service.EnrollTo(idPerson, cm);
                            if (enrollment != null)
                            {
                                enrollments.Add(enrollment);
                            }
                        }
                        if (enrollments.Where(e => e.Status == EnrolledStatus.Available || e.Status == EnrolledStatus.NeedConfirm).Any())
                        {
                            lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.BaseModules.CommunityManagement.Domain.CacheKeys.UserCommunitiesTree(idPerson));
                            enrollments.Where(e => e.Status == EnrolledStatus.Available || e.Status == EnrolledStatus.NeedConfirm).ToList().ForEach(e => View.NotifyEnrollment(e, person, profileType, organizationName));
                        }
                        if ((enrollments.Any() && enrollments.Where(s => s.Status == EnrolledStatus.NotAvailable || s.Status == EnrolledStatus.UnableToEnroll).Any()) ||
                            items.Where(i => i.HasConstraints || !i.AllowUnsubscribe).Any())
                        {
                            UpdateSelectedItems(enrollments.Where(e => e.Status == EnrolledStatus.Available || e.Status == EnrolledStatus.NeedConfirm || e.Status == EnrolledStatus.PreviousEnrolled || e.Status == EnrolledStatus.UnableToEnroll).Select(e => e.IdCommunity).ToList());
                            View.DisplayConfirmMessage(enrollments.Where(e => e.Status != EnrolledStatus.NotAvailable && e.Status != EnrolledStatus.UnableToEnroll).ToList(),
                                                       enrollments.Where(e => e.Status == EnrolledStatus.NotAvailable || e.Status == EnrolledStatus.UnableToEnroll).ToList(),
                                                       items.Where(i => !enrollments.Where(e => e.IdCommunity == i.Id).Any()).ToList(), person, profileType, organizationName);
                            View.SendUserAction(0, CurrentIdModule, items.Where(i => !enrollments.Where(e => e.IdCommunity == i.Id).Any()).Select(c => c.Id).ToList(), ModuleDashboard.ActionType.RequireEnrollConfirm);
                        }
                        else
                        {
                            if (enrollments.Where(e => e.Status == EnrolledStatus.Available).Any())
                            {
                                View.SendUserAction(0, CurrentIdModule, enrollments.Where(e => e.Status == EnrolledStatus.Available).Select(c => c.IdCommunity).ToList(), ModuleDashboard.ActionType.EnrollToCommunities);
                            }
                            if (enrollments.Where(e => e.Status == EnrolledStatus.NeedConfirm).Any())
                            {
                                View.SendUserAction(0, CurrentIdModule, enrollments.Where(e => e.Status == EnrolledStatus.NeedConfirm).Select(c => c.IdCommunity).ToList(), ModuleDashboard.ActionType.EnrollToCommunitiesWaitingConfirm);
                            }
                            UpdateSelectedItems(enrollments.Where(e => e.Status == EnrolledStatus.Available || e.Status == EnrolledStatus.NeedConfirm || e.Status == EnrolledStatus.PreviousEnrolled || e.Status == EnrolledStatus.UnableToEnroll).Select(e => e.IdCommunity).ToList());
                            if (enrollments.Any() && enrollments.Count == items.Count)
                            {
                                View.DisplayEnrollMessage(enrollments);
                            }
                            else
                            {
                                View.DisplayEnrollMessage(enrollments, items.Where(i => !enrollments.Where(e => e.IdCommunity == i.Id).Any()).Select(c => c.Name).ToList());
                            }
                        }
                    }
                }
                else
                {
                    View.SendUserAction(0, CurrentIdModule, sCommunities.Select(c => c.Id).ToList(), ModuleDashboard.ActionType.UnableToEnroll);
                }
                if (reloadCommunities)
                {
                    InternalLoadCommunities(itemsForPage, range, filters, orderBy, ascending, true, pageIndex, ModuleDashboard.ActionType.EnrollPageLoadcommunitiesAfterEnrolling);
                }
            }
        }
        public void EnrollTo(Int32 idCommunity, String name, String path, Int32 itemsForPage, RangeSettings range, lm.Comol.Core.BaseModules.CommunityManagement.dtoCommunitiesFilters filters, OrderItemsToSubscribeBy orderBy, Boolean ascending, Int32 pageIndex)
        {
            Int32 idPerson = UserContext.CurrentUserID;

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                Boolean reloadCommunities          = false;
                ModuleDashboard.ActionType dAction = ModuleDashboard.ActionType.None;
                dtoCommunityInfoForEnroll  item    = Service.GetEnrollingItem(idPerson, idCommunity, path);
                litePerson person = CurrentManager.GetLitePerson(idPerson);
                if (item != null && item.Id > 0 && person != null && person.Id > 0)
                {
                    if (!item.AllowEnroll)
                    {
                        dAction = ModuleDashboard.ActionType.EnrollNotAllowed;
                        View.DisplayEnrollMessage(item, dAction);
                    }
                    else
                    {
                        if (!item.HasConstraints && item.AllowUnsubscribe)
                        {
                            dtoEnrollment enrollment = Service.EnrollTo(idPerson, item);
                            if (enrollment == null)
                            {
                                dAction = ModuleDashboard.ActionType.UnableToEnroll;
                                View.DisplayEnrollMessage(item, dAction);
                            }
                            else
                            {
                                View.DisplayEnrollMessage(enrollment, enrollment.IdCommunity, person, Service.GetTranslatedProfileType(person), CurrentManager.GetUserDefaultOrganizationName(idPerson));
                                UpdateSelectedItems(new List <Int32>()
                                {
                                    enrollment.IdCommunity
                                });
                                reloadCommunities = true;
                                dAction           = (enrollment.Status == EnrolledStatus.NeedConfirm) ? ModuleDashboard.ActionType.EnrollToCommunityWaitingConfirm : ModuleDashboard.ActionType.EnrollToCommunity;
                                lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.BaseModules.CommunityManagement.Domain.CacheKeys.UserCommunitiesTree(idPerson));
                            }
                        }
                        else
                        {
                            dAction = ModuleDashboard.ActionType.RequireEnrollConfirm;
                            View.DisplayConfirmMessage(item);
                        }
                    }
                }
                else
                {
                    dAction = ModuleDashboard.ActionType.UnableToEnroll;
                    View.DisplayUnknownCommunity(name);
                }
                View.SendUserAction(0, CurrentIdModule, idCommunity, dAction);
                if (reloadCommunities)
                {
                    InternalLoadCommunities(itemsForPage, range, filters, orderBy, ascending, true, pageIndex, ModuleDashboard.ActionType.EnrollPageLoadcommunitiesAfterEnrolling);
                }
            }
        }