public static int UpdateStudent(Student student) { try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { //if (StudentDataManager.IsExistIdentityNumber(student.IdentityNumber, student.Id)) // throw new Exception("The identity number is already exist."); AddressManager.UpdateAddress(student.Address); BankManager.UpdateBank(student.Bank); student.ChildrenNumber = getNumberNotMarriedChildren(student.StudentChildren); student.MarriedChildrenNumber = getNumberMarriedChildren(student.StudentChildren); int update = StudentDataManager.UpdateStudent(student); if (student.StudentChildren != null) { foreach (StudentChildren child in student.StudentChildren) { if (!ValidateModel.IsValid(new List <object>() { child })) { throw new Exception("not valid child field/s"); } //if (child.Id > 0) // update = StudentChildrenDataManager.UpdateStudentChildren(child); //else //{ // child.Student.Id = student.Id; // child.Id = StudentChildrenDataManager.InsertStudentChildren(child); //} } } scope.Complete(); return(update); } } catch (Exception ex) { _logger.Debug($"Failed to update student {student.Id}.", ex); throw; } }
public static int InsertPendingStudent(Student student, int branchId, int?studyPathId) { try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { if (StudentDataManager.IsExistIdentityNumber(student.IdentityNumber, student.Id)) { throw new Exception("The identity number is already exist."); } student.Address.Id = AddressManager.InsertAddress(student.Address); student.Bank.Id = BankManager.InsertBank(student.Bank); //student.ChildrenNumber = getNumberNotMarriedChildren(student.StudentChildren); //student.MarriedChildrenNumber = getNumberMarriedChildren(student.StudentChildren); int insert = student.Id = StudentDataManager.InsertPendingStudent(student); if (student.StudentChildren != null) { foreach (StudentChildren child in student.StudentChildren) { if (!ValidateModel.IsValid(new List <object>() { child })) { throw new Exception("not valid child field/s"); } //i had this line child.Student = student; child.Student.Id = student.Id; child.Id = StudentChildrenDataManager.InsertStudentChildren(child); } } //BranchStudentManager.RequestRregistration(student.Id, branchId, studyPathId); scope.Complete(); return(insert); } } catch (Exception ex) { _logger.Debug($"Failed to insert pending student.", ex); throw; } }