Ejemplo n.º 1
0
        /// <summary>
        /// Copy Existing Site
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public void CopySite(int siteId)
        {
            if (!CheckSiteCollectionAdmin(UserContextDetails.UserId))
            {
                throw new BusinessException(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.UnAuthorized), CoreValidationMessagesConstants.UnAuthorized);
            }

            Site site = eCollabroDbContext.Repository<Site>().Query().Include(inc => inc.Navigations).Include(inc => inc.Roles).Filter(qry => qry.SiteId.Equals(siteId)).Get().FirstOrDefault();
            if (site != null)
            {
                #region Site Copy

                Site newSite = new Site();
                newSite.SiteName = site.SiteName + "-Copy";
                newSite.SiteDesc = site.SiteDesc;
                newSite.IsActive = true;
                newSite.SiteCode = _commonManager.GetNextCode(EntityConstants.Site);
                newSite.CreatedById = UserContextDetails.UserId;
                newSite.CreatedOn = DateTime.UtcNow;

                #endregion

                #region Feature Copy

                foreach (SiteFeature siteFeature in site.SiteFeatures)
                {
                    SiteFeature newsiteFeature = new SiteFeature();
                    newsiteFeature.FeatureId = siteFeature.FeatureId;
                    newsiteFeature.CreatedById = UserContextDetails.UserId;
                    newsiteFeature.CreatedOn = DateTime.UtcNow;
                    newSite.SiteFeatures.Add(newsiteFeature);
                }

                #endregion

                #region Navigation Copy

                foreach (Navigation navigation in site.Navigations)
                {
                    Navigation newNavigation = new Navigation();
                    newNavigation.NavigationCode = _commonManager.GetNextCode(EntityConstants.Navigation);
                    newNavigation.NavigationParentId = navigation.NavigationParentId;
                    newNavigation.ContentPageId = navigation.ContentPageId;
                    newNavigation.DisplayOrder = navigation.DisplayOrder;
                    newNavigation.IsAnomynousAccess = navigation.IsAnomynousAccess;
                    newNavigation.FeatureId = navigation.FeatureId;
                    newNavigation.NavigationText = navigation.NavigationText;
                    newNavigation.Link = navigation.Link;
                    newNavigation.IsActive = true;
                    newNavigation.IsDeleted = false;
                    newNavigation.NavigationTypeId = navigation.NavigationTypeId;
                    newNavigation.CreatedById = UserContextDetails.UserId;
                    newNavigation.CreatedOn = DateTime.UtcNow;
                    newSite.Navigations.Add(newNavigation);
                }

                #endregion

                #region Role Copy

                foreach (Role role in site.Roles)
                {
                    Role newRole = new Role();
                    newRole.RoleCode = _commonManager.GetNextCode(EntityConstants.Role);
                    newRole.RoleName = role.RoleName;
                    newRole.RoleDescription = role.RoleDescription;
                    newRole.IsSystem = role.IsSystem;
                    newRole.IsActive = true;
                    newRole.IsDeleted = false;
                    newRole.CreatedById = UserContextDetails.UserId;
                    newRole.CreatedOn = DateTime.UtcNow;
                    newSite.Roles.Add(newRole);
                }

                #endregion

                eCollabroDbContext.Repository<Site>().Insert(newSite);
                eCollabroDbContext.Save();

                #region Change Navigation Ids

                List<Navigation> fxNavition = site.Navigations.ToList();
                Dictionary<int, int?> dict = new Dictionary<int, int?>();
                for (int i = 0; i < fxNavition.Count; i++)
                {
                    if (fxNavition[i].NavigationParentId.HasValue)
                    {
                        int j = 0;
                        for (; j < fxNavition.Count; j++)
                        {
                            if (fxNavition[i].NavigationParentId.Value.Equals(fxNavition[j].NavigationId))
                            {
                                dict.Add(i, j);
                                break;
                            }
                        }

                    }
                    else
                    {
                        dict.Add(i, null);
                    }
                }

                for (int k = 0; k < dict.Count; k++)
                {
                    int? m;
                    dict.TryGetValue(k, out m);
                    if (m == null)
                    {
                        newSite.Navigations.ToList()[k].NavigationParentId = null;
                    }
                    else
                    {
                        newSite.Navigations.ToList()[k].NavigationParentId = newSite.Navigations.ToList()[m.Value].NavigationId;
                    }
                }

                eCollabroDbContext.Save();

                #endregion

            }
            else
            {
                throw new DBConcurrencyException();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// SaveSiteFeatures
        /// </summary>
        /// <param name="SiteFeatures"></param>
        private void SaveSiteFeatures(List<int> lstFeatures, int siteId)
        {
            List<SiteFeature> siteFeatures = eCollabroDbContext.Repository<SiteFeature>().Query().Filter(qry => qry.SiteId.Equals(siteId)).Get().ToList();
            foreach (int featureId in lstFeatures)
            {
                SiteFeature oldSiteFeature = siteFeatures.Where(ee => ee.FeatureId.Equals(featureId)).FirstOrDefault();
                if (oldSiteFeature == null) //New
                {
                    SiteFeature siteFeature = new SiteFeature();
                    siteFeature.FeatureId = featureId;
                    siteFeature.SiteId = siteId;
                    siteFeature.CreatedById = UserContextDetails.UserId;
                    siteFeature.CreatedOn = DateTime.UtcNow;
                    eCollabroDbContext.Repository<SiteFeature>().Insert(siteFeature);
                }
            }

            foreach (SiteFeature siteFeature in siteFeatures)
            {
                if (!lstFeatures.Contains(siteFeature.FeatureId))
                {
                    eCollabroDbContext.Repository<SiteFeature>().Delete(siteFeature);
                }
            }
            if (lstFeatures.Count == 0) // unselect the existing feature
            {
                foreach (SiteFeature siteFeature in siteFeatures)
                {
                    eCollabroDbContext.Repository<SiteFeature>().Delete(siteFeature);
                }
            }
            eCollabroDbContext.Save();
        }