private void ToggleWorkgroupHierarchyCheckbox()
        {
            // Parse the id of the workgroup from
            // the http request's parameters.
            Guid idWorkgroup = Guid.Parse(Request.Params["IdWorkgroup"]);

            // Parse the id of the hierarchy from
            // the http request's parameters.
            Guid idHierarchy = Guid.Parse(Request.Params["IdHierarchy"]);

            // Check if the hierarchy is asigned to the workgroup.
            if (Global.Core.WorkgroupHierarchies.GetCount(
                    new string[] { "IdWorkgroup", "IdHierarchy" },
                    new object[] { idWorkgroup, idHierarchy }
                    ) == 0)
            {
                WorkgroupHierarchy workgroupHierarchy = new WorkgroupHierarchy(Global.Core.WorkgroupHierarchies);
                workgroupHierarchy.IdWorkgroup = idWorkgroup;
                workgroupHierarchy.IdHierarchy = idHierarchy;

                workgroupHierarchy.Insert();
            }
            else
            {
                Global.Core.WorkgroupHierarchies.Delete((Guid)Global.Core.WorkgroupHierarchies.GetValue(
                                                            "Id",
                                                            new string[] { "IdWorkgroup", "IdHierarchy" },
                                                            new object[] { idWorkgroup, idHierarchy }
                                                            ));
            }
        }
Ejemplo n.º 2
0
        private Guid[] GetHierarchies(string path)
        {
            List <Guid> result = new List <Guid>();

            //Guid? result = null;

            string[] hierarchyPaths = path.Split(',');

            foreach (string hierarchyPath in hierarchyPaths)
            {
                string[] parts = hierarchyPath.Split('/');

                Guid?idHierarchy = null;
                for (int i = 0; i < parts.Length; i++)
                {
                    Hierarchy hierarchy = Global.Core.Hierarchies.GetSingle(
                        new string[] { "Name", "IdHierarchy" },
                        new object[] { parts[i], (idHierarchy.HasValue ? (object)idHierarchy.Value : null) }
                        );

                    if (hierarchy == null)
                    {
                        hierarchy = new Hierarchy(Global.Core.Hierarchies);

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

                        hierarchy.Insert();

                        WorkgroupHierarchy workgroupHierarchy = new WorkgroupHierarchy(Global.Core.WorkgroupHierarchies);
                        workgroupHierarchy.IdHierarchy = hierarchy.Id;
                        workgroupHierarchy.IdWorkgroup = (Guid)Global.Core.UserWorkgroups.GetValue(
                            "IdWorkgroup",
                            "IdUser",
                            Global.IdUser.Value
                            );

                        workgroupHierarchy.Insert();
                    }

                    idHierarchy = hierarchy.Id;
                }

                if (idHierarchy.HasValue)
                {
                    result.Add(idHierarchy.Value);
                }
            }

            return(result.ToArray());
        }
Ejemplo n.º 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();
        }