private void _VMMapToBo(CourseItem bo, CourseItemVM boVM) { bo.Id = boVM.Id; bo.Name = boVM.Name; bo.Description = boVM.Description; bo.SortCode = boVM.SortCode; }
private void _BoMapToVM(CourseItem bo, CourseItemVM boVM) { boVM.Id = bo.Id; boVM.Name = bo.Name; boVM.Description = bo.Description; boVM.SortCode = bo.SortCode; if (bo.ParentCourseItem != null) { boVM.ParentCourseItemId = bo.ParentCourseItem.Id.ToString(); boVM.ParentCourseItemName = bo.ParentCourseItem.Name; } if (bo.Course != null) { boVM.CourseId = bo.Course.Id.ToString(); boVM.CourseName = bo.Course.Name; } if (bo.CourseItemContent != null) { boVM.CourseItemContentID = bo.CourseItemContent.Id.ToString(); boVM.CourseItemContentName = bo.CourseItemContent.Name; } if (bo.Creator != null) { boVM.CreatorUserID = bo.Creator.Id.ToString(); boVM.CreatorUserName = bo.Creator.UserName; } }
public async Task <CourseItemVM> GetVM(Guid boId, Guid courseID) { var boVM = new CourseItemVM(); // 初始化数据对象 var bo = _boRepository.GetSingle(boId, x => x.ParentCourseItem, y => y.Course, w => w.CourseItemContent, z => z.Creator); if (bo == null) { bo = new CourseItem(); bo.Course = _courseRepository.GetSingle(courseID); boVM.IsNew = true; } else { boVM.IsNew = false; } // 映射基本的属性值 _BoMapToVM(bo, boVM); // 设置供前端下拉选项所需要的数据集合 await SetTypeItems(boVM, courseID); return(boVM); }
/// <summary> /// 设置与传入的视图模型相关的关联元素的集合值 /// </summary> /// <param name="boVM"></param> /// <param name="courseID"></param> /// <returns></returns> public async Task SetTypeItems(CourseItemVM boVM, Guid courseID) { var boCollection = await _boRepository.GetAllAsyn(y => y.Course.Id == courseID); boVM.ParentCourseItemCollection = SelfReferentialItemFactory <CourseItem> .GetCollection(boCollection.OrderBy(x => x.SortCode).ToList(), true); boVM.CourseItemCollection = PlainFacadeItemFactory <Course> .Get(_courseRepository); }
public async Task <bool> SaveBo(CourseItemVM boVM) { var bo = _boRepository.GetSingle(boVM.Id, y => y.Course, z => z.CourseItemContent); if (bo == null) { bo = new CourseItem(); } _VMMapToBo(bo, boVM); if (!String.IsNullOrEmpty(boVM.ParentCourseItemId)) { bo.ParentCourseItem = _boRepository.GetSingle(Guid.Parse(boVM.ParentCourseItemId)); } else { bo.ParentCourseItem = bo; } if (!String.IsNullOrEmpty(boVM.CourseId)) { bo.Course = _courseRepository.GetSingle(Guid.Parse(boVM.CourseId)); } else { bo.Course = _courseRepository.GetAll().FirstOrDefault(); } if (!String.IsNullOrEmpty(boVM.CourseItemContentID) && bo.CourseItemContent == null) { bo.CourseItemContent = _courseItemContentRepository.GetSingle(Guid.Parse(boVM.CourseItemContentID)); } if (!String.IsNullOrEmpty(boVM.CreatorUserID)) { bo.Creator = await _userManager.FindByIdAsync(boVM.CreatorUserID); } // 检查和创建缺省的单元内容 if (bo.CourseItemContent == null) { bo.CourseItemContent = new CourseItemContent() { Name = bo.Name } } ; else { bo.CourseItemContent.Name = bo.Name; } var saveResult = await _boRepository.AddOrEditAndSaveAsyn(bo); return(saveResult); }