//Loading filtered data private void LoadData(string name) { using (var db = new ApirsRepository <tblOutcrop>()) { try { Outcrops = new BindableCollection <tblOutcrop>(db.GetModelByExpression(outc => outc.outLocalName == name)); if (Outcrops.Count == 0) { SelectedOutcrop = new tblOutcrop(); SelectedOutcrop.outLocalName = name; } else if (Outcrops.Count > 1) { SelectedOutcrop = Outcrops.First(); } else { SelectedOutcrop = Outcrops.First(); } } catch { Outcrops = new BindableCollection <tblOutcrop>(); SelectedOutcrop = new tblOutcrop(); } } }
public void Update() { using (var db = new ApirsRepository <tblOutcrop>()) { try { if (SelectedOutcrop.outIdPk == 0) { try { db.InsertModel(SelectedOutcrop); db.Save(); } catch { ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Object can't be added. Please check every field again."); return; } } else { tblOutcrop result = db.GetModelById(SelectedOutcrop.outIdPk); if (result != null) { db.UpdateModel(SelectedOutcrop, SelectedOutcrop.outIdPk); } } } catch (SqlException ex) { ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Please provide valid input parameters"); } catch (Exception e) { _events.PublishOnUIThreadAsync(new MessageBoxMessage(UserMessageValueConverter.ConvertBack(1), "", MessageBoxViewType.Error, MessageBoxViewButton.Ok));; } finally { } } }