/// <summary> /// Refreshing the dataset /// </summary> public override void Refresh() { try { if (!DataValidation.CheckPrerequisites(CRUD.Add)) { return; } } catch { return; } tblProject current = SelectedProject; int id = 0; try { if (SelectedProject != null) { id = SelectedProject.prjIdPk; } LoadData((int)((ShellViewModel)IoC.Get <IShell>()).UserId); SelectedProject = Projects.Where(p => p.prjIdPk == id).First(); } catch { try { LoadData((int)((ShellViewModel)IoC.Get <IShell>()).UserId); SelectedProject = new tblProject() { prjCreatorIdFk = (int)((ShellViewModel)IoC.Get <IShell>()).UserId }; } catch { ((ShellViewModel)IoC.Get <IShell>()).ShowError("An unexpeced error occured."); } } }
//Loading filtered data private void LoadData(int id) { using (var db = new ApirsRepository <tblProject>()) { try { Projects = new BindableCollection <tblProject>(db.GetModelByExpression(x => x.prjCreatorIdFk == id)); if (Projects.Count == 0) { SelectedProject = new tblProject() { prjCreatorIdFk = (int)((ShellViewModel)IoC.Get <IShell>()).UserId }; } else if (Projects.Count > 1) { SelectedProject = Projects.First(); } else { SelectedProject = Projects.First(); } } catch (Exception e) { Projects = new BindableCollection <tblProject>(); SelectedProject = new tblProject() { prjCreatorIdFk = (int)((ShellViewModel)IoC.Get <IShell>()).UserId }; } try { ParticipatingProjects = new BindableCollection <tblProject>(db.GetProjectByParticipation((int)((ShellViewModel)IoC.Get <IShell>()).UserId)); } catch { ParticipatingProjects = new BindableCollection <tblProject>(); } } }
/// <summary> /// Deleting the currently viewed rock sample /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Delete() { try { if (!DataValidation.CheckPrerequisites(CRUD.Delete, SelectedProject, (int)SelectedProject.prjCreatorIdFk)) { return; } } catch { return; } if (((ShellViewModel)IoC.Get <IShell>()).ShowQuestion("Are you sure to delete the record?") == MessageBoxViewResult.No) { return; } using (var db = new ApirsRepository <tblProject>()) { try { tblProject result = db.GetModelByExpression(p => p.prjIdPk == SelectedProject.prjIdPk).First(); if (result != null) { db.DeleteModelById(result.prjIdPk); } _events.PublishOnUIThreadAsync(new ChangeUserMessage((int)((ShellViewModel)IoC.Get <IShell>()).UserId, "")); LoadData((int)((ShellViewModel)IoC.Get <IShell>()).UserId); } catch (Exception ex) { ((ShellViewModel)IoC.Get <IShell>()).ShowError("An unexpeced error occured."); } finally { } } }
// Sets up the form so that user can enter data. Data is later // saved when user clicks Commit. public void Add() { try { if (!DataValidation.CheckPrerequisites(CRUD.Add)) { return; } } catch { return; } SelectedProject = new tblProject() { prjCreatorIdFk = (int)((ShellViewModel)IoC.Get <IShell>()).UserId }; SelectedProject.prjCreatorIdFk = (int)((ShellViewModel)IoC.Get <IShell>()).UserId; }