//Loading filtered data
 private void LoadData(string name)
 {
     using (var db = new ApirsRepository <tblHandpiece>())
     {
         try
         {
             Handpieces = new BindableCollection <tblHandpiece>(db.GetModelByExpression(hp => hp.hpLabelFk == name));
             if (Handpieces.Count == 0)
             {
                 SelectedHandpiece           = new tblHandpiece();
                 SelectedHandpiece.hpLabelFk = name;
             }
             else if (Handpieces.Count > 1)
             {
                 SelectedHandpiece = Handpieces.First();
             }
             else
             {
                 SelectedHandpiece = Handpieces.First();
             }
         }
         catch
         {
             Handpieces        = new BindableCollection <tblHandpiece>();
             SelectedHandpiece = new tblHandpiece();
         }
     }
 }
 public void Update()
 {
     using (var db = new ApirsRepository <tblHandpiece>())
     {
         try
         {
             if (SelectedHandpiece.hpIdPk == 0)
             {
                 try
                 {
                     db.InsertModel(SelectedHandpiece);
                     db.Save();
                     TryClose();
                 }
                 catch
                 {
                     ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Handpiece can't be added. Please check every field again.");
                     return;
                 }
             }
             else
             {
                 tblHandpiece result = db.GetModelById(SelectedHandpiece.hpIdPk);
                 if (result != null)
                 {
                     db.UpdateModel(SelectedHandpiece, SelectedHandpiece.hpIdPk);
                     db.Save();
                 }
             }
         }
         catch (SqlException ex)
         {
             ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Please provide valid input parameters");
         }
         catch (Exception e)
         {
             ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Something went wrong");
         }
         finally
         {
         }
     }
 }