コード例 #1
0
        private void AssignWorkgroups(Guid idUser)
        {
            // Get all workgroups of the client.
            List <object[]> workgroups = Global.Core.Workgroups.GetValues(
                new string[] { "Id" },
                new string[] { },
                new object[] { }
                );

            //ctl00$cphContent$chkUserWorkgroup

            // Run through all workgroups of the client.
            foreach (object[] workgroup in workgroups)
            {
                if (Request.Params["ctl00$cphContent$chkUserWorkgroup" + workgroup[0]] == null)
                {
                    if (Global.Core.UserWorkgroups.GetCount(
                            new string[] { "IdWorkgroup", "IdUser" },
                            new object[] { workgroup[0], idUser }
                            ) > 0)
                    {
                        Global.Core.UserWorkgroups.Delete((Guid)Global.Core.UserWorkgroups.GetValue(
                                                              "Id",
                                                              new string[] { "IdWorkgroup", "IdUser" },
                                                              new object[] { workgroup[0], idUser }
                                                              ));
                    }

                    continue;
                }


                // Check if the user is asigned to the workgroup.
                if (Global.Core.UserWorkgroups.GetCount(
                        new string[] { "IdWorkgroup", "IdUser" },
                        new object[] { workgroup[0], idUser }
                        ) == 0)
                {
                    UserWorkgroup workgroupHierarchy = new UserWorkgroup(Global.Core.UserWorkgroups);
                    workgroupHierarchy.IdWorkgroup = (Guid)workgroup[0];
                    workgroupHierarchy.IdUser      = idUser;

                    workgroupHierarchy.Insert();
                }
            }
        }
コード例 #2
0
        protected void btnAddWorkgroupConfirm_Click(object sender, EventArgs e)
        {
            Workgroup workgroup = new Workgroup(Global.Core.Workgroups);

            workgroup.Name         = txtAddWorkgroupName.Text.Trim();
            workgroup.CreationDate = DateTime.Now;

            workgroup.Insert();

            UserWorkgroup userWorkgroup = new UserWorkgroup(Global.Core.UserWorkgroups);

            userWorkgroup.IdUser      = Global.IdUser.Value;
            userWorkgroup.IdWorkgroup = workgroup.Id;

            userWorkgroup.Insert();

            Response.Redirect(Request.Url.ToString());
        }
コード例 #3
0
        private void InsertHierarchy()
        {
            // Parse the id of the parent hierarchy
            // from the http request's parameters.
            Guid idHierarchy = Guid.Parse(Request.Params["IdHierarchy"]);

            // Create a new hierarchy object.
            Hierarchy hierarchy = new Hierarchy(Global.Core.Hierarchies);

            hierarchy.IdHierarchy = idHierarchy;
            hierarchy.Name        = Request.Params["Name"];
            hierarchy.SetValue("CreationDate", DateTime.Now);

            hierarchy.Insert();

            // Parse the id of the workgroup where to assign the
            // hierarchy to from the http request's parameters.
            Guid idWorkgroup;

            if (!Guid.TryParse(Request.Params["IdWorkgroup"], out idWorkgroup))
            {
                Workgroup workgroup = new Workgroup(Global.Core.Workgroups);
                workgroup.CreationDate = DateTime.Now;
                workgroup.Name         = "Default";

                workgroup.Insert();

                idWorkgroup = workgroup.Id;

                UserWorkgroup userWorkgroup = new UserWorkgroup(Global.Core.UserWorkgroups);
                userWorkgroup.IdWorkgroup = idWorkgroup;
                userWorkgroup.IdUser      = Global.IdUser.Value;

                userWorkgroup.Insert();
            }

            WorkgroupHierarchy workgroupHierarchy = new WorkgroupHierarchy(Global.Core.WorkgroupHierarchies);

            workgroupHierarchy.IdHierarchy = hierarchy.Id;
            workgroupHierarchy.IdWorkgroup = idWorkgroup;

            workgroupHierarchy.Insert();
        }