/// <summary> /// Initializes a new instance of the <see cref="AppletItemDTO"/> class. /// </summary> /// <param name="result"> /// The result. /// </param> public AppletItemDTO(AppletItem result) { this.appletItemId = result.Id; this.subModuleItemId = result.SubModuleItem.Return(x => x.Id, (int?)null); this.appletName = result.AppletName; this.documentXML = result.DocumentXML; }
private AppletItem ConvertDto(AppletItemDTO itemDTO, AppletItem instance) { instance = instance ?? new AppletItem(); instance.AppletName = itemDTO.appletName; instance.DocumentXML = itemDTO.documentXML; instance.SubModuleItem = itemDTO.subModuleItemId.HasValue ? this.SubModuleItemModel.GetOneById(itemDTO.subModuleItemId.Value).Value : null; if (instance.SubModuleItem != null) { instance.SubModuleItem.DateModified = DateTime.Now; this.SubModuleItemModel.RegisterSave(instance.SubModuleItem); } return(instance); }
/// <summary> /// The get applet sub module items by user id. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// The <see cref="IEnumerable{SubModuleItem}"/>. /// </returns> public IEnumerable <SubModuleItemDTO> GetAppletSubModuleItemsByUserId(int userId) { SubModuleItemFromStoredProcedureDTO dto = null; SubModuleItem smi = null; SubModuleCategory smc = null; AppletItem appletItem = null; SubModuleItemTheme theme = null; var queryOver = new DefaultQueryOver <SubModuleItem, int>().GetQueryOver(() => smi) .JoinQueryOver(x => x.SubModuleCategory, () => smc) .JoinQueryOver(() => smi.AppletItems, () => appletItem) .JoinQueryOver(() => smi.Themes, () => theme, JoinType.LeftOuterJoin) .Where(() => smi.CreatedBy != null && smi.CreatedBy.Id == userId && smc.User != null && smc.User.Id == userId) .SelectList(res => res.Select(() => smi.CreatedBy.Id) .WithAlias(() => dto.createdBy) .Select(() => smi.Id) .WithAlias(() => dto.subModuleItemId) .Select(() => smc.SubModule.Id) .WithAlias(() => dto.subModuleId) .Select(() => smi.SubModuleCategory.Id) .WithAlias(() => dto.subModuleCategoryId) .Select(() => smi.IsShared) .WithAlias(() => dto.isShared) .Select(() => smi.ModifiedBy.Id) .WithAlias(() => dto.modifiedBy) .Select(() => smi.DateCreated) .WithAlias(() => dto.dateCreated) .Select(() => smi.DateModified) .WithAlias(() => dto.dateModified) .Select(() => smi.IsActive) .WithAlias(() => dto.isActive) .Select(() => theme.Id) .WithAlias(() => dto.themeId)) .TransformUsing(Transformers.AliasToBean <SubModuleItemFromStoredProcedureDTO>()); var result = this.Repository.FindAll <SubModuleItemFromStoredProcedureDTO>(queryOver) .ToList() .Select(x => new SubModuleItemDTO(x)) .ToList(); var themeIds = result.Where(x => x.themeId.HasValue).Select(x => x.themeId.Value).ToList(); var themeQuery = new DefaultQueryOver <SubModuleItemTheme, int>().GetQueryOver().WhereRestrictionOn(x => x.Id).IsIn(themeIds); var themes = this.themeRepository.FindAll(themeQuery).ToList(); result.ForEach(x => x.themeVO = x.themeId.HasValue ? themes.FirstOrDefault(t => t.Id == x.themeId).Return(tt => new SubModuleItemThemeDTO(tt), null) : null); return(result); }
/// <summary> /// The get applet categories by user id. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// The <see cref="IEnumerable{SubModuleCategoryDTO}"/>. /// </returns> public IEnumerable <SubModuleCategoryDTO> GetAppletCategoriesByUserId(int userId) { SubModuleItem smi = null; SubModuleCategory smc = null; AppletItem ai = null; SubModuleCategoryFromStoredProcedureDTO dto = null; var queryOver = new DefaultQueryOver <SubModuleCategory, int>().GetQueryOver(() => smc) .JoinQueryOver(x => x.SubModuleItems, () => smi, JoinType.InnerJoin) .JoinQueryOver(() => smi.AppletItems, () => ai, JoinType.LeftOuterJoin) .Where(() => smc.User.Id == userId && smi.CreatedBy.Id == userId && ai.Id != 0) .SelectList(res => res.Select(Projections.Distinct(Projections.ProjectionList() .Add(Projections.Property(() => smc.IsActive)) .Add(Projections.Property(() => smc.DateModified)) .Add(Projections.Property(() => smc.ModifiedBy.Id)) .Add(Projections.Property(() => smc.CategoryName)) .Add(Projections.Property(() => smc.SubModule.Id)) .Add(Projections.Property(() => smc.User.Id)) .Add(Projections.Property(() => smc.Id)) )) .Select(() => smc.IsActive) .WithAlias(() => dto.isActive) .Select(() => smc.DateModified) .WithAlias(() => dto.dateModified) .Select(() => smc.ModifiedBy.Id) .WithAlias(() => dto.modifiedBy) .Select(() => smc.CategoryName) .WithAlias(() => dto.categoryName) .Select(() => smc.SubModule.Id) .WithAlias(() => dto.subModuleId) .Select(() => smc.User.Id) .WithAlias(() => dto.userId) .Select(() => smc.Id) .WithAlias(() => dto.subModuleCategoryId)) .TransformUsing(Transformers.AliasToBean <SubModuleCategoryFromStoredProcedureDTO>()); var result = this.Repository.FindAll <SubModuleCategoryFromStoredProcedureDTO>(queryOver) .ToList() .Select(x => new SubModuleCategoryDTO(x)); return(result); }