//===================THIS METHOD IS FOR ADD RECORDS SUBJECTS TABLE============== public void AddSubj(string newSubName) { Subj.SubName = newSubName; using (StudentuConteiner db = new StudentuConteiner()) { try { var res2 = db.Subjects.Any(o => o.SubName == Subj.SubName); if (!res2) { if (!string.IsNullOrEmpty(Subj.SubName) || Subj.SubName != "---") { Subj.SubName.Trim(); if (Subj.SubName[0] == ' ') { dialogService.ShowMessage("Нельзя добавить пустую строку"); return; } db.Subjects.Add(Subj); db.SaveChanges(); SubjRecords.Clear(); LoadSubjectsData(); Subj = new Subject(); SelectedSubj2 = Subj; } else { return; } } else { dialogService.ShowMessage("Уже есть такое название в базе данных"); } } catch (ArgumentNullException ex) { dialogService.ShowMessage(ex.Message); } catch (OverflowException ex) { dialogService.ShowMessage(ex.Message); } catch (System.Data.SqlClient.SqlException ex) { dialogService.ShowMessage(ex.Message); } catch (System.Data.Entity.Core.EntityCommandExecutionException ex) { dialogService.ShowMessage(ex.Message); } catch (System.Data.Entity.Core.EntityException ex) { dialogService.ShowMessage(ex.Message); } } }
//===================THIS METHOD IS FOR EDIT RECORDS IN SUBJECTS TABLE============== public void EditSubj(string newSubName) { if (Subj.SubName == "---") { dialogService.ShowMessage("Нельзя редактировать эту запись"); return; } Subj.SubName = newSubName; using (StudentuConteiner db = new StudentuConteiner()) { try { var res2 = db.Subjects.Find(Subj.SubjectId); if (res2 != null) { //changing DB res2.SubName = Subj.SubName; db.SaveChanges(); SubjRecords.Clear(); LoadSubjectsData(); } } catch (ArgumentNullException ex) { dialogService.ShowMessage(ex.Message); } catch (OverflowException ex) { dialogService.ShowMessage(ex.Message); } catch (System.Data.SqlClient.SqlException ex) { dialogService.ShowMessage(ex.Message); } catch (System.Data.Entity.Core.EntityCommandExecutionException ex) { dialogService.ShowMessage(ex.Message); } catch (System.Data.Entity.Core.EntityException ex) { dialogService.ShowMessage(ex.Message); } } }