public static void NewEwithS(int idExpertise, SubjectDto subjectDto) { using (placementDepartmentDBEntities placementDepartmentDB = new placementDepartmentDBEntities()) { Expertise expertise = placementDepartmentDB.Expertise.Find(idExpertise); Subject subject = placementDepartmentDB.Subject.Find(subjectDto.Id); if (!expertise.Subject.Contains(subject)) { expertise.Subject.Add(subject); placementDepartmentDB.SaveChanges(); } else { throw new Exception("Duplicate"); } } }
public static void DeleteExpertise(int id) { using (placementDepartmentDBEntities placementDepartmentDB = new placementDepartmentDBEntities()) { try { Expertise expertise = placementDepartmentDB.Expertise.Find(id); placementDepartmentDB.Expertise.Remove(expertise); placementDepartmentDB.SaveChanges(); } catch (DbUpdateException ex) { var sqlException = ex.GetBaseException() as SqlException; if (sqlException != null) { if (sqlException.Number == 547) { throw new DbUpdateException("547"); } } } } }