Esempio 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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Save Role
        /// </summary>
        /// <param name="role"></param>
        public void SaveRole(Role role)
        {
            #region Check Permission

            List<PermissionEnum> userPermissions = GetUserFeaturePermissions(UserContextDetails.UserId, FeatureEnum.Role);
            if ((role.RoleId.Equals(0) && !userPermissions.Contains(PermissionEnum.AddContent)) || (!role.RoleId.Equals(0) && !userPermissions.Contains(PermissionEnum.EditContent)))
                throw new BusinessException(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.UnAuthorized), CoreValidationMessagesConstants.UnAuthorized);

            #endregion

            if (role.RoleId.Equals(0))
            {
                role.RoleCode = _commonManager.GetNextCode(EntityConstants.Role);
                role.SiteId = UserContextDetails.SiteId;
                role.CreatedById = UserContextDetails.UserId;
                role.CreatedOn = DateTime.UtcNow;
                eCollabroDbContext.Repository<Role>().Insert(role);
                eCollabroDbContext.Save();
            }
            else
            {
                Role oldRole = eCollabroDbContext.Repository<Role>().Query().Filter(flt => flt.RoleId.Equals(role.RoleId)).Get().FirstOrDefault();
                if (oldRole != null)
                {
                    if (oldRole.IsSystem)
                        throw new BusinessException(string.Format(_coreValidationResourceManager.GetString(CoreValidationMessagesConstants.SystemDefinedValue), "Role"), CoreValidationMessagesConstants.SystemDefinedValue.ToString());
                    oldRole.RoleName = role.RoleName;
                    oldRole.RoleDescription = role.RoleDescription;
                    oldRole.ModifiedById = UserContextDetails.UserId;
                    oldRole.ModifiedOn = DateTime.UtcNow;
                    oldRole.IsActive = role.IsActive;
                    eCollabroDbContext.Save();
                }
                else
                {
                    throw new DBConcurrencyException();
                }
            }
        }