public void Update() { SchoolDisplayModel exists = Schools.Where(x => x.Id == SelectedSchool.Id).FirstOrDefault(); if (exists != null) { if (SelectedSchool != null && Schools.Count > 0) { isUpdating = true; SchoolModel e = new SchoolModel { Id = SelectedSchool.Id, SchoolName = _schoolName, SchoolCode = _schoolCode, Phone = _phone, Location = _location }; SqlDataAccess sql = new SqlDataAccess(); sql.UpdateData <SchoolModel>("dbo.spSchool_Update", e, "ADBData"); msg = $"School ({SelectedSchool.SchoolName}) was successfully updated."; MessageBox.Show(msg, "School Updated"); Schools = new BindingList <SchoolDisplayModel>(GetAllSchools()); Clear(); isUpdating = false; _events.PublishOnUIThread(new SchoolChangedEvent()); } } }
public void Add() { isAdding = true; SchoolDisplayModel e = Schools.Where(x => x.SchoolName == SchoolName && x.SchoolCode == SchoolCode).FirstOrDefault(); if (e == null) { SqlDataAccess sql = new SqlDataAccess(); sql.SaveData <dynamic>("dbo.spSchool_Insert", new { SchoolName = _schoolName, SchoolCode = _schoolCode, Phone = _phone, Location = _location }, "ADBData"); Schools = new BindingList <SchoolDisplayModel>(GetAllSchools()); NotifyOfPropertyChange(() => Schools); Clear(); _events.PublishOnUIThread(new SchoolChangedEvent()); } else { msg = $"Error: An School named ({SelectedSchool.SchoolName}) already exist!!!"; MessageBox.Show(msg, "Error"); } isAdding = false; }
public void Delete() { SchoolDisplayModel e = Schools.Where(x => x.Id == SelectedSchool.Id).FirstOrDefault(); if (e != null) { SqlDataAccess sql = new SqlDataAccess(); sql.DeleteData <dynamic>("dbo.spSchool_Delete", new { Id = SelectedSchool.Id }, "ADBData"); Schools = new BindingList <SchoolDisplayModel>(GetAllSchools()); SelectedSchool = null; Clear(); _events.PublishOnUIThread(new SchoolChangedEvent()); } }