Beispiel #1
0
        /// <summary>
        /// This method inserts a new record in the table.
        /// Change this method to alter how records are inserted.
        /// </summary>
        /// <param name=entity>entity</param>
        public void Insert(PackageFunction entity)
        {
            DbContext.PackageFunctions.InsertOnSubmit(entity);
            DbContext.SubmitChanges();


            var rManager = new RolesManager(this);
            IQueryable <Role> queryAdminRoles = (from companies in DbContext.Companies
                                                 join roles in DbContext.Roles on companies.CompanyId equals
                                                 roles.CompanyId
                                                 join plan in DbContext.Plans on companies.PlanId equals plan.PlanId
                                                 where plan.PackageId == entity.PackageId && roles.Name.Contains("Admin")
                                                 select roles);


            List <Role> listAdminRoles = queryAdminRoles.ToList();

            var permissionManager = new PermissionManager(this);

            foreach (Role role in listAdminRoles)
            {
                if (permissionManager.GetPermission(entity.FunctionId, role.RoleId, role.CompanyId) == null)
                {
                    var permission = new Permission();
                    permission.CompanyId        = role.CompanyId;
                    permission.FunctionId       = entity.FunctionId;
                    permission.PermissionTypeId = (int)AccessControlActions.Change;
                    permission.RoleId           = role.RoleId;
                    permissionManager.Insert(permission);
                }
            }
        }
        /// <summary>
        /// Method to create a new role of "ADMIN" type
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        private Role CreateAdminRole(int companyId)
        {
            var rolesManager = new RolesManager(this);
            var role = new Role();

            role.ApplicationId = Application.Current.ApplicationId;
            role.Name = "Admin";
            role.Description = "Administrador";
            role.LastUpdatedDate = DateTime.Now;
            role.CompanyId = companyId;
            rolesManager.Insert(role);

            //
            // Update the Role Admin in Company
            //
            Company company = GetCompany(companyId);
            company.RoleAdminId = role.RoleId;
            DbContext.SubmitChanges();

            return role;
        }