Ejemplo n.º 1
0
        public ActionResult QueryLayoutTreeDeletePartial(long id)
        {
            //все проверки в CanDelete
            List <AvrTreeElement> tree = GetQueryTree();
            AvrTreeElement        node = tree.FirstOrDefault(c => c.ID == id);
            string errStr = String.Empty;

            try
            {
                if (node != null)
                {
                    if (node.IsFolder)
                    {
                        //AvrQueryLayoutTreeDbHelper.DeleteFolder(node.ID);
                        using (var avrDbService = new Folder_DB())
                        {
                            avrDbService.Delete(node.ID);
                        }
                    }
                    else if (node.IsLayout)
                    {
                        using (var avrDbService = new WebLayoutDB())
                        {
                            avrDbService.Delete(node.ID);
                        }
                    }

                    RefreshTree();
                }
            }
            catch (Exception exc)
            {
                errStr = exc.Message;
            }
            return(PartialView("QueryLayoutTreePartial", GetQueryTree()));

            /*
             * return new JsonResult
             * {
             *  JsonRequestBehavior = JsonRequestBehavior.AllowGet,
             *  Data = new
             *  {
             *      result = errStr.Length == 0 ? "OK" : "ERROR",
             *      errorString = errStr
             *  }
             * };
             */
        }
Ejemplo n.º 2
0
        public void CreateModifyDeleteFoldersTest()
        {
            lock (m_SyncLock)
            {
                EidssUserContext.CheckUserLoggedIn();

                PresenterFactory.SharedPresenter.SharedModel.SelectedQueryId = m_TestQueryId;

                List <AvrTreeElement> original = AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId);

                AvrTreeElement folder1 = CreateFolderItem(null, "Folder1", "Nat f1");
                AvrQueryLayoutTreeDbHelper.SaveFolder(folder1.ID, folder1.ParentID, m_TestQueryId, folder1.DefaultName, folder1.NationalName);
                AvrTreeElement folder2 = CreateFolderItem(null, "Folder2", "Nat f2");
                AvrQueryLayoutTreeDbHelper.SaveFolder(folder2.ID, folder2.ParentID, m_TestQueryId, folder2.DefaultName, folder2.NationalName);
                AvrTreeElement folder3 = CreateFolderItem(null, "Folder3", "Nat f3");
                AvrQueryLayoutTreeDbHelper.SaveFolder(folder3.ID, folder3.ParentID, m_TestQueryId, folder3.DefaultName, folder3.NationalName);

                LookupManager.ClearAndReloadOnIdle();

                List <AvrTreeElement> saved1 = AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId);
                Assert.AreEqual(original.Count + 3, saved1.Count, "some folders not saved");

                AvrTreeElement savedFolder1 = saved1.Find(ById(folder1.ID));
                Assert.IsNotNull(savedFolder1);
                AvrTreeElement savedFolder2 = saved1.Find(ById(folder2.ID));
                Assert.IsNotNull(savedFolder2);
                AvrTreeElement savedFolder3 = saved1.Find(ById(folder3.ID));
                Assert.IsNotNull(savedFolder3);

                Assert.AreEqual(m_TestQueryId, savedFolder1.ParentID);
                Assert.AreEqual(m_TestQueryId, savedFolder2.ParentID);
                Assert.AreEqual(m_TestQueryId, savedFolder3.ParentID);

                AvrQueryLayoutTreeDbHelper.SaveFolder(savedFolder2.ID, savedFolder1.ID,
                                                      m_TestQueryId, savedFolder2.DefaultName, savedFolder2.NationalName);
                AvrQueryLayoutTreeDbHelper.SaveFolder(savedFolder3.ID, savedFolder2.ID,
                                                      m_TestQueryId, savedFolder3.DefaultName, savedFolder3.NationalName);

                LookupManager.ClearAndReloadOnIdle();

                List <AvrTreeElement> saved2 = AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId);

                AvrTreeElement updatedFolder2 = saved2.Find(ById(folder2.ID));
                Assert.IsNotNull(updatedFolder2);
                AvrTreeElement updatedFolder3 = saved2.Find(ById(folder3.ID));
                Assert.IsNotNull(updatedFolder3);
                Assert.AreEqual(folder1.ID, updatedFolder2.ParentID);
                Assert.AreEqual(folder2.ID, updatedFolder3.ParentID);

                int oldFoldersCount = AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId).Count;

                // delete saved folders

                using (var avrDbService = new Folder_DB())
                {
                    Assert.IsTrue(avrDbService.Delete(folder3.ID),
                                  string.Format("could not delete folder '{0}' because of '{1}'", folder3.ID, avrDbService.LastError));
                    Assert.IsTrue(avrDbService.Delete(folder2.ID),
                                  string.Format("could not delete folder '{0}' because of '{1}'", folder2.ID, avrDbService.LastError));
                    Assert.IsTrue(avrDbService.Delete(folder1.ID),
                                  string.Format("could not delete folder '{0}' because of '{1}'", folder1.ID, avrDbService.LastError));
                }

                LookupManager.ClearAndReloadOnIdle();

                Assert.AreEqual(oldFoldersCount - 3, AvrQueryLayoutTreeDbHelper.ReLoadFolders(false, m_TestQueryId).Count);
            }
        }
Ejemplo n.º 3
0
        public void UpdateFoldersTest()
        {
            lock (m_SyncLock)
            {
                PresenterFactory.SharedPresenter.SharedModel.SelectedQueryId = m_TestQueryId;
                long layoutId = CreateLayout();
                try
                {
                    List <AvrTreeElement> original = AvrQueryLayoutTreeDbHelper.LoadQueries();
                    original.AddRange(AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId));
                    EidssUserContext.CheckUserLoggedIn();
                    original.AddRange(AvrQueryLayoutTreeDbHelper.LoadLayouts(false, m_TestQueryId));
                    var final = new List <AvrTreeElement>(original);

                    AvrTreeElement layout = original.Find(ById(layoutId));
                    Assert.IsNotNull(layout);

                    AvrTreeElement folder1 = CreateFolderItem(null, "Folder1", "Nat f1");
                    AvrQueryLayoutTreeDbHelper.SaveFolder(folder1.ID, folder1.ParentID, m_TestQueryId, folder1.DefaultName,
                                                          folder1.NationalName);

                    AvrTreeElement folder2 = CreateFolderItem(folder1.ID, "Folder2", "Nat f2");
                    AvrQueryLayoutTreeDbHelper.SaveFolder(folder2.ID, folder2.ParentID, m_TestQueryId, folder2.DefaultName,
                                                          folder2.NationalName);

                    AvrTreeElement folder3 = CreateFolderItem(folder2.ID, "Folder3", "Nat f3");
                    AvrQueryLayoutTreeDbHelper.SaveFolder(folder3.ID, folder3.ParentID, m_TestQueryId, folder3.DefaultName,
                                                          folder3.NationalName);

                    final.AddRange(new[] { folder1, folder2, folder3 });
                    layout.ParentID = folder1.ID;

                    LookupManager.ClearAndReloadOnIdle();
                    List <AvrTreeElement> saved = AvrQueryLayoutTreeDbHelper.LoadQueries();
                    saved.AddRange(AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId));
                    EidssUserContext.CheckUserLoggedIn();
                    saved.AddRange(AvrQueryLayoutTreeDbHelper.LoadLayouts(false, m_TestQueryId));

                    AvrTreeElement newFolder1 = saved.Find(ById(folder1.ID));
                    Assert.IsNotNull(newFolder1);
                    AvrTreeElement newFolder2 = saved.Find(ById(folder2.ID));
                    Assert.IsNotNull(newFolder2);
                    AvrTreeElement newFolder3 = saved.Find(ById(folder3.ID));
                    Assert.IsNotNull(newFolder3);
                    AvrTreeElement newLayout = saved.Find(ById(layoutId));
                    Assert.IsNotNull(newLayout);
                    Assert.AreEqual(m_TestQueryId, newFolder1.ParentID);
                    Assert.AreEqual(newFolder1.ID, newFolder2.ParentID);
                    Assert.AreEqual(newFolder2.ID, newFolder3.ParentID);
                    Assert.AreEqual(m_TestQueryId, newLayout.ParentID);
                    newLayout.ParentID = m_TestQueryId;
                    layout.ParentID    = m_TestQueryId;

                    LookupManager.ClearAndReloadOnIdle();
                    int oldFoldersCount = AvrQueryLayoutTreeDbHelper.LoadFolders(false, m_TestQueryId).Count;

                    // delete saved folders

                    using (var avrDbService = new Folder_DB())
                    {
                        Assert.IsTrue(avrDbService.Delete(folder3.ID),
                                      string.Format("could not delete folder '{0}' because of '{1}'", folder3.ID, avrDbService.LastError));
                        Assert.IsTrue(avrDbService.Delete(folder2.ID),
                                      string.Format("could not delete folder '{0}' because of '{1}'", folder2.ID, avrDbService.LastError));
                        Assert.IsTrue(avrDbService.Delete(folder1.ID),
                                      string.Format("could not delete folder '{0}' because of '{1}'", folder1.ID, avrDbService.LastError));
                    }
                    LookupManager.ClearAndReloadOnIdle();
                    Assert.AreEqual(oldFoldersCount - 3, AvrQueryLayoutTreeDbHelper.ReLoadFolders(false, m_TestQueryId).Count);
                }
                finally
                {
                    DeleteLayout(layoutId);
                }
            }
        }