//===================THIS METHOD IS FOR ADD RECORDS IN WORKTYPE TABLES============== public void AddWorkType(string newName) { WorkType.TypeOfWork = newName; using (StudentuConteiner db = new StudentuConteiner()) { try { var res = db.WorkTypes.Any(o => o.TypeOfWork == WorkType.TypeOfWork); if (!res) { if (!string.IsNullOrEmpty(WorkType.TypeOfWork) || WorkType.TypeOfWork != "---") { WorkType.TypeOfWork = WorkType.TypeOfWork.ToLower(); WorkType.TypeOfWork.Trim(); if (WorkType.TypeOfWork[0] == ' ') { dialogService.ShowMessage("Нельзя добавить пустую строку"); return; } db.WorkTypes.Add(WorkType); db.SaveChanges(); WorkTypesRecords.Clear(); LoadWorkTypesData(); WorkType = new WorkType(); } 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 WORKTYPES TABLES============== public void EditWorkType(string newName) { if (WorkType.TypeOfWork == "---") { dialogService.ShowMessage("Нельзя редактировать эту запись"); return; } WorkType.TypeOfWork = newName; using (StudentuConteiner db = new StudentuConteiner()) { try { var res = db.WorkTypes.Find(WorkType.WorkTypeId); if (res != null) { //changing DB res.TypeOfWork = WorkType.TypeOfWork.ToLower(); db.SaveChanges(); WorkTypesRecords.Clear(); LoadWorkTypesData(); } } 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); } } }