public async Task <CreateOrUpdateCourseDto> GetForEdit(NullableIdDto <long> input) { var output = new CreateOrUpdateCourseDto(); if (input.Id.HasValue) { var entity = await _courseManager.QueryAsNoTracking .Where(e => e.Id == input.Id.Value) .Include(e => e.CourseCategories) .FirstOrDefaultAsync(); if (entity == null) { throw new UserFriendlyException("抱歉!未找到对应课程"); } output.Entity = ObjectMapper.Map <CourseDto>(entity); //output.CategoryIds = entity.CourseCategories.Select(e => e.CourseCategoryId).ToList(); output.CategoryIds = await _courseToCourseCategoryManager.GetCateByCourseId(entity.Id) .ToListAsync(); } else { output.Entity = new CourseDto(); } output.CourseStateEnum = _enumExtensionsAppService .GetEntityDoubleStringKeyValueList <CourseStateEnum>(); output.CourseDisplayTypeEnum = _enumExtensionsAppService.GetEntityDoubleStringKeyValueList <CourseTypeEnum>(); output.CourseVideoTypeEnum = _enumExtensionsAppService.GetEntityDoubleStringKeyValueList <CourseVideoTypeEnum>(); return(output); }
public async Task CreateOrUpdate(CreateOrUpdateCourseDto input) { if (input.Entity.Id.HasValue) { await Update(input.Entity); } else { input.Entity = await Create(input.Entity); } await _courseToCourseCategoryManager .UpdateCourseToCategory(input.Entity.Id.Value, input.CategoryIds.ToArray()); }