//Loading filtered data private void LoadData(string name) { using (var db = new ApirsDatabase()) { try { Drillings = new BindableCollection <tblDrilling>(from drill in db.tblDrillings where drill.drillName == name select drill); if (Drillings.Count == 0) { SelectedDrilling = new tblDrilling(); SelectedDrilling.drillName = name; } else if (Drillings.Count > 1) { SelectedDrilling = Drillings.First(); } else { SelectedDrilling = Drillings.First(); } } catch { Drillings = new BindableCollection <tblDrilling>(); SelectedDrilling = new tblDrilling(); } } }
//Loading filtered data private void LoadData(string name) { using (var db = new ApirsRepository <tblDrilling>()) { try { Drillings = new BindableCollection <tblDrilling>(db.GetModelByExpression(x => x.drillName == name)); if (Drillings.Count == 0) { SelectedDrilling = new tblDrilling(); SelectedDrilling.drillName = name; } else if (Drillings.Count > 1) { SelectedDrilling = Drillings.First(); } else { SelectedDrilling = Drillings.First(); } } catch { Drillings = new BindableCollection <tblDrilling>(); SelectedDrilling = new tblDrilling(); } } }
// Commit changes from the new object form // or edits made to the existing object form. public void Update() { using (var db = new ApirsDatabase()) { try { if (SelectedDrilling.drillIdPk == 0) { try { db.tblDrillings.Add(SelectedDrilling); db.SaveChanges(); TryClose(); } catch { ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Object can't be added. Please check every field again."); return; } } else { tblDrilling result = db.tblDrillings.Where(drill => drill.drillName == SelectedDrilling.drillName).First(); if (result != null) { db.Entry <tblDrilling>(result).CurrentValues.SetValues(SelectedDrilling); db.SaveChanges(); } } } 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 { } } }