BExIS.Web.Shell.Areas.Sam.Controllers.DatasetController.Purge C# (CSharp) Method

Purge() public method

Purges a dataset, which means the dataset and all its versions will be physically removed from the database.
This operation is not revocerable.
public Purge ( long id ) : System.Web.Mvc.ActionResult
id long the identifier of the dataset to be purged.
return System.Web.Mvc.ActionResult
        public ActionResult Purge(long id)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Purge", this.Session.GetTenant());
            bool itsFine = false;
            DatasetManager dm = new DatasetManager();
            try
            {
                if (dm.PurgeDataset(id))
                {
                    itsFine = true;
                }
            }
            catch (Exception ex)
            {
                try // give it another try
                {
                    if (dm.PurgeDataset(id, true))
                    {
                        itsFine = true;
                    }
                }
                catch (Exception exx)
                {
                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} could not be purged. Details: {1}, see also: {2}", id, exx.Message, ex.Message));
                }
            }

            if (itsFine)
            {
                try
                {
                    PermissionManager pm = new PermissionManager();
                    pm.DeleteDataPermissionsByEntity(1, id);
                }
                catch
                {
                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} was purged, but its permissions were not altered. You need to remove them manually from the data permission management.", id));
                }
                try
                {
                    ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider;
                    provider?.UpdateSingleDatasetIndex(id, IndexingAction.DELETE);
                }
                catch
                {
                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} was purged, but it is still indexed for searching. You need to reindex the search via the managemnet console.", id));
                }
            }
            return View();
        }