コード例 #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);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// This method delete a function from a package
        /// </summary>
        /// <param name="packageId"></param>
        /// <param name="functionId"></param>
        public void DeletePackageFunctions(int packageId, int functionId)
        {
            PackageFunction entity =
                DbContext.PackageFunctions.Where(x => x.FunctionId == functionId && x.PackageId == packageId).
                FirstOrDefault();

            DbContext.PackageFunctions.DeleteOnSubmit(entity);
            DbContext.SubmitChanges();
        }
コード例 #3
0
        /// <summary>
        /// This method inserts a Function in a package
        /// </summary>
        /// <param name="packageId"></param>
        /// <param name="functionId"></param>
        /// <returns></returns>
        public InsertPackageFunctionsStatus InsertPackageFunctions(int packageId, int functionId)
        {
            var entity = new PackageFunction();

            entity.PackageId  = packageId;
            entity.FunctionId = functionId;
            try
            {
                DbContext.PackageFunctions.InsertOnSubmit(entity);
                DbContext.SubmitChanges();
            }
            catch
            {
                return(InsertPackageFunctionsStatus.DuplicateEntry);
            }
            return(InsertPackageFunctionsStatus.Success);
        }
コード例 #4
0
        /// <summary>
        /// This method deletes a record in the table.
        /// Change this method to alter how records are deleted.
        /// </summary>
        /// <param name=entity>entity</param>
        public void Delete(PackageFunction entity)
        {
            IQueryable <Permission> query = from permissions in DbContext.Permissions
                                            join company in DbContext.Companies on permissions.CompanyId equals
                                            company.CompanyId
                                            join plan in DbContext.Plans on company.PlanId equals plan.PlanId
                                            where
                                            plan.PackageId == entity.PackageId &&
                                            permissions.FunctionId == entity.FunctionId
                                            select permissions;

            DbContext.Permissions.DeleteAllOnSubmit(query);
            DbContext.SubmitChanges();


            DbContext.PackageFunctions.Attach(entity);
            DbContext.PackageFunctions.DeleteOnSubmit(entity);
            DbContext.SubmitChanges();
        }
コード例 #5
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Int32 packageId = Convert.ToInt32(Request["PackageId"]);

        IEnumerable <Function> functionsByPackage = (Session["FunctionPackage"] as List <Function>).AsEnumerable();

        IEnumerable <Function> selectedFunctions = dlbFunctions.SelectedItems.Cast <ListItem>()
                                                   .Select(li => new Function()
        {
            FunctionId = Convert.ToInt32(li.Value)
        });

        foreach (Function function in from fp in functionsByPackage.AsEnumerable()
                 where !selectedFunctions.Any(func => func.FunctionId == fp.FunctionId)
                 select fp)
        {
            using (PackageFunctionManager manager = new PackageFunctionManager(null))
            {
                PackageFunction pFunction = new PackageFunction();
                pFunction.FunctionId = function.FunctionId;
                pFunction.PackageId  = packageId;

                manager.Delete(pFunction);
            }
        }

        foreach (Function function in from fp in selectedFunctions
                 where !functionsByPackage.AsEnumerable().Any(func => func.FunctionId == fp.FunctionId)
                 select fp)
        {
            using (PackageFunctionManager manager = new PackageFunctionManager(null))
            {
                PackageFunction packageFunction = new PackageFunction();
                packageFunction.PackageId  = packageId;
                packageFunction.FunctionId = function.FunctionId;

                manager.Insert(packageFunction);
            }
        }
        dlbFunctions.DataBind();
    }
コード例 #6
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Int32 packageId = Convert.ToInt32(Request["PackageId"]);

        IEnumerable<Function> functionsByPackage = (Session["FunctionPackage"] as List<Function>).AsEnumerable();

        IEnumerable<Function> selectedFunctions = dlbFunctions.SelectedItems.Cast<ListItem>()
            .Select(li => new Function()
            {
                FunctionId = Convert.ToInt32(li.Value)
            });

        foreach (Function function in from fp in functionsByPackage.AsEnumerable()
                                      where !selectedFunctions.Any(func => func.FunctionId == fp.FunctionId)
                                      select fp)
            using (PackageFunctionManager manager = new PackageFunctionManager(null))
            {
                PackageFunction pFunction = new PackageFunction();
                pFunction.FunctionId = function.FunctionId;
                pFunction.PackageId = packageId;

                manager.Delete(pFunction);
            }

        foreach (Function function in from fp in selectedFunctions
                                      where !functionsByPackage.AsEnumerable().Any(func => func.FunctionId == fp.FunctionId)
                                      select fp)
            using (PackageFunctionManager manager = new PackageFunctionManager(null))
            {
                PackageFunction packageFunction = new PackageFunction();
                packageFunction.PackageId = packageId;
                packageFunction.FunctionId = function.FunctionId;

                manager.Insert(packageFunction);
            }
        dlbFunctions.DataBind();

    }
コード例 #7
0
 /// <summary>
 /// This method updates a record in the table.
 /// Change this method to alter how records are updated.
 /// </summary>
 /// <param name=original_entity>original_entity</param>
 /// <param name=entity>entity</param>
 public void Update(PackageFunction original_entity, PackageFunction entity)
 {
     DbContext.PackageFunctions.Attach(original_entity);
     DbContext.SubmitChanges();
 }