public static SchoolObject ConvertToSchoolObject(Group group) { return new SchoolObject { Id = group.Id, Name = group.Name }; }
public static ConnectedSchoolObject ConvertToConnectedSchoolObject(Group group, long parentId) { return new ConnectedSchoolObject { Id = group.Id, Name = group.Name, ParentId = parentId }; }
public OperationResult DeleteProfessor(long professorId) { return OperationResult.Invoke(() => { using (var dataBase = CreateConnection()) { using (var transaction = dataBase.Database.BeginTransaction()) { try { var professor = new Group {Id = professorId}; dataBase.GroupSet.Attach(professor); dataBase.GroupSet.Remove(professor); // delete connections foreach (var professorSubject in dataBase.ProfessorsSubjectSet.Where(x => x.ProfessorId == professorId)) { dataBase.ProfessorsSubjectSet.Remove(professorSubject); } dataBase.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }); }
public OperationResult<SchoolObject> CreateGroup(SchoolObject group) { return OperationResult.Invoke(() => { using (var dataBase = CreateConnection()) { var groupEntity = new Group { Name = group.Name }; dataBase.GroupSet.Add(groupEntity); dataBase.SaveChanges(); return ModelConverter.ConvertToSchoolObject(groupEntity); } }); }