/// <summary>
        /// Refreshing the dataset
        /// </summary>
        public override void Refresh()
        {
            LithostratigraphyUnion current = SelectedLithostratigraphy;

            try
            {
                string selected = SelectedLithostratigraphy.grName;
                LoadData();
                LoadData(SelectedLithostratigraphy.Hierarchy.ToString());
                SelectedLithostratigraphy = Lithostratigraphies.Where(x => x.grName == selected).First();
            }
            catch
            {
                try
                {
                    LoadData();
                    LoadData("Group");
                    SelectedLithostratigraphy = new LithostratigraphyUnion();
                }
                catch
                {
                    ((ShellViewModel)IoC.Get <IShell>()).ShowError("An unexpected error occured.");
                }
            }
        }
 /// <summary>
 /// Go to the first dataset
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void First()
 {
     if (Lithostratigraphies.Count != 0)
     {
         SelectedLithostratigraphy = Lithostratigraphies.First();
     }
 }
        /// <summary>
        /// Deleting the currently viewed rock sample
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Delete()
        {
            try
            {
                if (!DataValidation.CheckPrerequisites(CRUD.Delete, SelectedLithostratigraphy, SelectedLithostratigraphy.UploaderId))
                {
                    return;
                }
            }
            catch
            {
                return;
            }


            if (((ShellViewModel)IoC.Get <IShell>()).ShowQuestion("Are you sure to delete the record?",
                                                                  "You won't be able to retrieve the related measurement data after deleting this sample.") == MessageBoxViewResult.No)
            {
                return;
            }
            try
            {
                switch (SelectedLithostratigraphy.Hierarchy)
                {
                case "Group":
                    tblGroup result = new ApirsRepository <tblGroup>().GetModelByExpression(b => b.grName == SelectedLithostratigraphy.grName).First();

                    if (result != null)
                    {
                        new ApirsRepository <tblGroup>().DeleteModelById(result.grIdPk);
                    }
                    break;

                case "Subgroup":
                    tblSubgroup result1 = new ApirsRepository <tblSubgroup>().GetModelByExpression(b => b.sgName == SelectedLithostratigraphy.grName).First();

                    if (result1 != null)
                    {
                        new ApirsRepository <tblSubgroup>().DeleteModelById(result1.sgIdPk);
                    }
                    break;

                case "Formation":
                    tblFormation result2 = new ApirsRepository <tblFormation>().GetModelByExpression(b => b.fmName == SelectedLithostratigraphy.grName).First();

                    if (result2 != null)
                    {
                        new ApirsRepository <tblFormation>().DeleteModelById(result2.fmIdPk);
                    }
                    break;

                case "Subformation":
                    tblSubformation result3 = new ApirsRepository <tblSubformation>().GetModelByExpression(b => b.sfName == SelectedLithostratigraphy.grName).First();

                    if (result3 != null)
                    {
                        new ApirsRepository <tblSubformation>().DeleteModelById(result3.sfIdPk);
                    }
                    break;
                }

                tblUnionLithostratigraphy result4 = new ApirsRepository <tblUnionLithostratigraphy>().GetModelByExpression(b => b.grName == SelectedLithostratigraphy.grName).First();

                if (result4 != null)
                {
                    new ApirsRepository <tblUnionLithostratigraphy>().DeleteModelById(result4.ID);
                }

                Lithostratigraphies.Remove(SelectedLithostratigraphy);
                allLithostratigraphies.Remove(SelectedLithostratigraphy);
                SelectedLithostratigraphy = Lithostratigraphies.FirstOrDefault();
            }
            catch (Exception ex)
            {
                _events.PublishOnUIThreadAsync(new MessageBoxMessage(UserMessageValueConverter.ConvertBack(1), "", MessageBoxViewType.Error, MessageBoxViewButton.Ok));;
            }
            finally
            {
            }
        }