Esempio n. 1
0
 //Loading filtered data
 private void LoadData(string name)
 {
     using (var db = new ApirsRepository <tblThinSection>())
     {
         try
         {
             ThinSections = new BindableCollection <tblThinSection>(db.GetModelByExpression(ts => ts.tsFromSample == name));
             if (ThinSections.Count == 0)
             {
                 SelectedThinSection = new tblThinSection();
                 SelectedThinSection.tsFromSample = name;
             }
             else if (ThinSections.Count > 1)
             {
                 SelectedThinSection = ThinSections.First();
             }
             else
             {
                 SelectedThinSection = ThinSections.First();
             }
         }
         catch
         {
             ThinSections        = new BindableCollection <tblThinSection>();
             SelectedThinSection = new tblThinSection();
             SelectedThinSection.tsFromSample = name;
         }
     }
 }
Esempio n. 2
0
 public void Update()
 {
     using (var db = new ApirsRepository <tblThinSection>())
     {
         try
         {
             if (SelectedThinSection.tsIdPk == 0)
             {
                 try
                 {
                     db.InsertModel(SelectedThinSection);
                     db.Save();
                     TryClose();
                 }
                 catch
                 {
                     ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Thin section can't be added. Please check every field again.");
                     return;
                 }
             }
             else
             {
                 tblThinSection result = db.GetModelById(SelectedThinSection.tsIdPk);
                 if (result != null)
                 {
                     db.UpdateModel(SelectedThinSection, SelectedThinSection.tsIdPk);
                     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
         {
         }
     }
 }