//Loading filtered data
 private void LoadData(string name)
 {
     using (var db = new ApirsRepository <tblPowder>())
     {
         try
         {
             Powders = new BindableCollection <tblPowder>(db.GetModelByExpression(pow => pow.powFromSampleName == name));
             if (Powders.Count == 0)
             {
                 SelectedPowder = new tblPowder();
                 SelectedPowder.powFromSampleName = name;
             }
             else if (Powders.Count > 1)
             {
                 SelectedPowder = Powders.First();
             }
             else
             {
                 SelectedPowder = Powders.First();
             }
         }
         catch
         {
             Powders        = new BindableCollection <tblPowder>();
             SelectedPowder = new tblPowder();
         }
     }
 }
 public void Update()
 {
     using (var db = new ApirsRepository <tblPowder>())
     {
         try
         {
             if (SelectedPowder.powIdPk == 0)
             {
                 try
                 {
                     db.InsertModel(SelectedPowder);
                     db.Save();
                     TryClose();
                 }
                 catch
                 {
                     ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Powder can't be added. Please check every field again.");
                     return;
                 }
             }
             else
             {
                 tblPowder result = db.GetModelById(SelectedPowder.powIdPk);
                 if (result != null)
                 {
                     db.UpdateModel(SelectedPowder, SelectedPowder.powIdPk);
                     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
         {
         }
     }
 }