Exemplo n.º 1
0
        public void AddOrganizationStructure(string OrgListName, OrgStructureEntityModel newOrg, Action<bool, Exception> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            List list = _client.Web.Lists.GetByTitle(OrgListName);

            ListItem listItem = list.AddItem(new ListItemCreationInformation());            
            listItem["Title"] = newOrg.Title;
            listItem["ParentID"] = newOrg.ParentID;
            listItem["LevelName"] = newOrg.LevelName.ToString();
            listItem["OrderNo"] = newOrg.OrderNo;
            listItem["Inactive"] = newOrg.IsActive ? "No" : ""; 
            listItem.Update();
            
            SuccessHandler = (s, e) =>
            {
                newOrg.ID = listItem.Id;
                newOrg.OriginalTitle = newOrg.Title;
                reply(true, null);
            };

            FailureHandler = (s, e) =>
            {
                Logger.AddLog(_log, e.Exception);
                reply(false, e.Exception);
            };

            _client.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }
Exemplo n.º 2
0
        private void AddGlobalAction()
        {
            DefaultDisable(); 

            OrgStructureEntityModel newOrg = new OrgStructureEntityModel();
            newOrg.Title = Constants.GlobalFunction;
            newOrg.LevelName = OrgStructureEntityModel.LevelNames.GlobalFunction;
            newOrg.DataMode = OrgStructureEntityModel.Mode.Add;
            newOrg.OrderNo = Levels.Count > 0 ? Levels.Count : 1;
            Levels.Add(newOrg);
        }
Exemplo n.º 3
0
 internal static OrgStructureEntityModel GetInstance(ListItem item)
 {
     OrgStructureEntityModel newOrg = new OrgStructureEntityModel();            
     newOrg.ID = item.Id;
     newOrg.IsActive = (bool)GetPropertyValue(item.FieldValues[Columns.Inactive], Columns.Inactive);
     newOrg.LevelName = (OrgStructureEntityModel.LevelNames)GetPropertyValue(item.FieldValues[Columns.Level], Columns.Level);
     newOrg.OrderNo = Int32.Parse(GetPropertyValue(item.FieldValues[Columns.OrderNo], Columns.OrderNo).ToString());
     newOrg.ParentID = Int32.Parse(GetPropertyValue(item.FieldValues[Columns.ParentID], Columns.ParentID).ToString());            
     newOrg.Title = GetPropertyValue(item.FieldValues[Columns.Title], Columns.Title).ToString();
     newOrg.OriginalTitle = newOrg.Title;
     return newOrg;
 }
Exemplo n.º 4
0
        private void AddAction()
        {
            IsError = false;
            if (_selectedOrgStructureEntityModel != null)
            {
                DefaultDisable(); 

                 _selectedTreeViewItem.IsExpanded = true;

                OrgStructureEntityModel newOrg = new OrgStructureEntityModel();
                newOrg.DataMode = OrgStructureEntityModel.Mode.Add;

                if (_selectedOrgStructureEntityModel.LevelName == OrgStructureEntityModel.LevelNames.GlobalFunction)
                {
                    newOrg.Title = Constants.AssetCategory;
                    newOrg.LevelName = OrgStructureEntityModel.LevelNames.AssetCategory;               
                }
                else if (_selectedOrgStructureEntityModel.LevelName == OrgStructureEntityModel.LevelNames.AssetCategory)
                {
                    newOrg.Title =Constants.BusinessArea;
                    newOrg.LevelName = OrgStructureEntityModel.LevelNames.BusinessArea;                  
                }
                newOrg.Parent = _selectedOrgStructureEntityModel;
                newOrg.ParentID = _selectedOrgStructureEntityModel.ID;
                newOrg.OrderNo = _selectedOrgStructureEntityModel.Children.Count > 0 ? _selectedOrgStructureEntityModel.Children.Count : 1;
                _selectedOrgStructureEntityModel.Add(newOrg);                
            }            
        }
Exemplo n.º 5
0
        private bool RecursiveDuplicateCheck(OrgStructureEntityModel Source, OrgStructureEntityModel org)
        {            
            bool result = false;

            if (org != null)
            {
                if (Source != org && Source.Title.Trim().ToLower() == org.Title.Trim().ToLower() && Source.LevelName == org.LevelName)
                    return true;
                else
                {
                    foreach (OrgStructureEntityModel child in Source.Children)
                    {
                        result = RecursiveDuplicateCheck(child, org);
                        if (result == true) return result;
                    }
                }
            }
            
            return result;
        }
Exemplo n.º 6
0
        private bool IsDuplicateItem(OrgStructureEntityModel org)
        {
            bool result = false;

            if (org != null)
            {
                foreach (OrgStructureEntityModel child in Levels)
                {
                    result = RecursiveDuplicateCheck(child, org);
                    if (result == true) return result;
                }
                
            }
            return result;
        }
Exemplo n.º 7
0
 public void SaveOrgStructure(OrgStructureEntityModel Org)
 {
     IsError = false;
     if (Org.Title.ToLower() != (Org.OriginalTitle != null ?Org.OriginalTitle.ToLower():Org.OriginalTitle))
     {               
         if (!IsDuplicateItem(Org))
         {
             if (Org.DataMode == OrgStructureEntityModel.Mode.Add)
                 AddNewItemToOrgStructureList(Org);
             else if (Org.DataMode == OrgStructureEntityModel.Mode.Edit)
                 EditItemFromOrgStructureList(Org);
             else
             {
                 IsError = true;
                 ErrorMessage = "Invalid Operation!";
             }
         }
         else
         {
             if (Org.DataMode == OrgStructureEntityModel.Mode.Add)
             {
                 if (Org.LevelName == OrgStructureEntityModel.LevelNames.GlobalFunction)                        
                     Org.SetTitle(Constants.GlobalFunction);                        
                 else if (Org.LevelName == OrgStructureEntityModel.LevelNames.AssetCategory)
                     Org.SetTitle(Constants.AssetCategory);                        
                 else
                     Org.SetTitle(Constants.BusinessArea);                        
            }
             else
                 Org.SetTitle(Org.OriginalTitle);
             
             IsError = true;
             ErrorMessage = "Item Already Exist!";
            
         }
     }
     DefaultEnable();
 }
Exemplo n.º 8
0
        private void DeleteItemFromOrgStructureList(OrgStructureEntityModel deleteOrg)
        {
                IsBusy = true;
                IsError = false;                
                _OrgStructureServiceAgent.IntegrityCheckOrganizationStructure(deleteOrg, _mainCheckListName, _subSiteUrl, (oreply, oe) =>
                {
                      _dispatcher.BeginInvoke(new Action(() =>
                                {
                                    if (oreply == true && oe == null)
                                    {
                                        _OrgStructureServiceAgent.DeleteOrganizationStructure(Constants.OrgStructure, deleteOrg, (reply, e) =>
                                        {
                                               _dispatcher.BeginInvoke(new Action(() =>
                                                {
                                                    if (e != null && reply == false)
                                                    {
                                                        IsError = true;
                                                        ErrorMessage = Logger.BuildLogMessageForUser(e, "Delete Item Failed!");
                                                        IsBusy = false;
                                                    }
                                                    else
                                                    {
                                                        if (deleteOrg.Parent != null)
                                                            deleteOrg.Parent.Delete(deleteOrg);
                                                        else
                                                            Levels.Remove(deleteOrg);

                                                        _selectedOrgStructureEntityModel = null;
                                                        _selectedTreeViewItem = null;
                                                        IsBusy = false;
                                                    }                                                   
                                                }));
                                            
                                        });
                                    }
                                    else
                                    {
                                        IsError = true;
                                        ErrorMessage = Logger.BuildLogMessageForUser(oe, "Item did not pass integrity check!");
                                        IsBusy = false;
                                    }
                                   
                                }));
                });
            DefaultEnable();
        }
Exemplo n.º 9
0
        private void EditItemFromOrgStructureList(OrgStructureEntityModel editOrg)
        {
            IsBusy = true;
            IsError = false;
            
            _OrgStructureServiceAgent.IntegrityCheckOrganizationStructure(editOrg,_mainCheckListName,_subSiteUrl,(oreply,oe)=>
                {
                      _dispatcher.BeginInvoke(new Action(() =>
                                {
                                    if (oreply == true && oe == null)
                                    {
                                        _OrgStructureServiceAgent.EditOrganizationStructure(Constants.OrgStructure, editOrg, (reply, e) =>
                                        {
                                            _dispatcher.BeginInvoke(new Action(() =>
                                                {
                                                    if (e != null && reply == false)
                                                    {                                                                                                                
                                                        IsError = true;
                                                        ErrorMessage = Logger.BuildLogMessageForUser(e, "Edit Item Failed!");                                                       
                                                    }
                                                    
                                                    IsBusy = false;
                                                }));
                                        });
                                    }
                                    else
                                    {
                                            IsError = true;
                                            ErrorMessage = Logger.BuildLogMessageForUser(oe,"Item did not pass integrity check!");
                                            editOrg.SetTitle(editOrg.OriginalTitle);
                                    }
                                    IsBusy = false;
                                }));
                });

            
        }
Exemplo n.º 10
0
 private void AddNewItemToOrgStructureList(OrgStructureEntityModel newOrg)
 {
     IsBusy = true;
     _OrgStructureServiceAgent.AddOrganizationStructure(Constants.OrgStructure, newOrg, (reply, e) =>
     {
         _dispatcher.BeginInvoke(new Action(() =>
             {
                 if (e != null && reply == false)
                 {
                     IsError = true;
                     ErrorMessage = Logger.BuildLogMessageForUser(e, "Add Item Failed!");
                 }                        
                 IsBusy = false;
             })); 
     });
 }
Exemplo n.º 11
0
        private void AddChildren(OrgStructureEntityModel parent, List<ListItem> items)
        {
            var children = from item in items
                           where Int32.Parse(OrgStructureFactory.GetPropertyValue(item.FieldValues[Columns.ParentID],
                           Columns.ParentID).ToString()) == parent.ID
                           orderby Int32.Parse(OrgStructureFactory.GetPropertyValue(item.FieldValues[Columns.OrderNo],
                           Columns.OrderNo).ToString())
                           select OrgStructureFactory.GetInstance(item, parent);

            foreach (OrgStructureEntityModel org in children.ToList<OrgStructureEntityModel>())
            {
                parent.Children.Add(org);
                AddChildren(org, items);
            }
        }
Exemplo n.º 12
0
        public void IntegrityCheckOrganizationStructure(OrgStructureEntityModel Org, string listName, string subSiteUrl, Action<bool, Exception> reply)
        {
            const string BUSINESS_AREA_COLUMN = "Business_x0020_Area";
            const string ASSET_CATEGORY_COLUMN = "Asset_x0020_Category";

            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            CamlQuery query = new CamlQuery();
            ClientContext _ctx;
            string field = string.Empty;

            if (Org.LevelName == OrgStructureEntityModel.LevelNames.AssetCategory ||
                Org.LevelName == OrgStructureEntityModel.LevelNames.BusinessArea)
            {
                if (Org.LevelName == OrgStructureEntityModel.LevelNames.AssetCategory)
                    field = ASSET_CATEGORY_COLUMN;
                else if (Org.LevelName == OrgStructureEntityModel.LevelNames.BusinessArea)
                    field = BUSINESS_AREA_COLUMN;
                else
                    field = "";

                query.ViewXml = BuildQuery(field, Org.OriginalTitle);
                _ctx = new ClientContext(subSiteUrl);

                ListItemCollection orgList = _ctx.Web.Lists.GetByTitle(listName).GetItems(query);
                _ctx.Load(orgList);

                SuccessHandler = (s, e) =>
                {
                    if (orgList != null && orgList.Count > 0)
                    {
                        Org.Title = Org.OriginalTitle;
                        reply(false, null);
                    }
                    else
                    {
                        reply(true, null);
                    }
                };

                FailureHandler = (s, e) =>
                {
                    Logger.AddLog(_log, e.Exception);
                    reply(false, e.Exception);
                };

                _ctx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
            }
            else
                reply(true, null);

        }      
Exemplo n.º 13
0
        public void DeleteOrganizationStructure(string OrgListName, OrgStructureEntityModel deleteOrg, Action<bool, Exception> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            ListItem listItem = _client.Web.Lists.GetByTitle(OrgListName).GetItemById(deleteOrg.ID);
            listItem.DeleteObject();

            SuccessHandler = (s, e) =>
            {
                reply(true, null);
            };

            FailureHandler = (s, e) =>
            {
                Logger.AddLog(_log, e.Exception);
                reply(false, e.Exception);
            };

            _client.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }