/// <summary> /// 保存Education信息(新增/更新) /// </summary> /// <param name="updateForeignKey">更新时是否更新外键信息</param> /// <param name="dtos">要保存的EducationDto信息</param> /// <returns>业务操作集合</returns> public async Task <OperationResult> SaveEducations(bool updateForeignKey = false, params EducationDto[] dtos) { try { dtos.CheckNotNull("dtos"); var addDtos = dtos.Where(p => p.Id == 0).ToArray(); var updateDtos = dtos.Where(p => p.Id != 0).ToArray(); EducationRepo.UnitOfWork.TransactionEnabled = true; Action <EducationDto> checkAction = null; Func <EducationDto, Education, Education> updateFunc = null; if (addDtos.Length > 0) { EducationRepo.Insert(addDtos, checkAction, updateFunc); } if (updateDtos.Length > 0) { EducationRepo.Update(updateDtos, checkAction, updateFunc); } await EducationRepo.UnitOfWork.SaveChangesAsync(); return(new OperationResult(OperationResultType.Success, "保存成功")); } catch (Exception e) { return(new OperationResult(OperationResultType.Error, e.Message)); } }
private void btnStaffSave_Click(object sender, RoutedEventArgs e) { if (FormMode == FormModes.View) { this.ActualParent.Close(); return; } if (FormMode == FormModes.New) { int _newUserID = UserRepo.Insert(User); UserDetail.UserID = _newUserID; UserDetail.created_by = Utilities.UserSession.UserID; UserDetail.updated_by = Utilities.UserSession.UserID; UserDetailRepo.Insert(UserDetail); foreach (var exp in ExperienceList) { exp.UserID = _newUserID; ExperienceRepo.Insert(exp); } foreach (var edu in EducationList) { edu.UserID = _newUserID; EducationRepo.Insert(edu); } } else { UserDetailRepo.Update(UserDetail); UserRepo.Update(User); foreach (var exp in ExperienceList) { if (exp.isNew) { exp.UserID = User.UserID; ExperienceRepo.Insert(exp); } else { ExperienceRepo.Update(exp); } } foreach (var edu in EducationList) { if (edu.isNew) { edu.UserID = User.UserID; EducationRepo.Insert(edu); } else { EducationRepo.Update(edu); } } } this.ActualParent.Close(); }