Example #1
0
        /// <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> GetQuizSMItemsByUserId(int userId)
        {
            QueryOver <User, User> query =
                new DefaultQueryOver <User, int>().GetQueryOver()
                .Where(x => x.Id == userId)
                .Select(res => res.Company.Id);
            IFutureValue <int> companyId = this.userRepository.FindOne <int>(query);

            SubModuleItemFromStoredProcedureDTO dto = null;
            SubModuleItem     smi    = null;
            SubModuleCategory smc    = null;
            Quiz quiz                = null;
            SubModuleItemTheme theme = null;
            User u         = null;
            var  queryOver =
                new DefaultQueryOver <SubModuleItem, int>().GetQueryOver(() => smi)
                .JoinQueryOver(x => x.SubModuleCategory, () => smc)
                .JoinQueryOver(() => smi.Quizes, () => quiz)
                .JoinQueryOver(() => smi.Themes, () => theme, JoinType.LeftOuterJoin)
                .JoinQueryOver(() => smc.User, () => u, JoinType.InnerJoin)
                .Where(() => smi.CreatedBy != null && smc.User != null && ((smi.CreatedBy.Id == userId && smc.User.Id == userId) ||
                                                                           (u.Company.Id == companyId.Value && quiz.LmsQuizId != null)))
                .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);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubModuleItemThemeDTO"/> class.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 public SubModuleItemThemeDTO(SubModuleItemTheme result)
 {
     this.subModuleItemId = result.With(x => x.SubModuleItem.Id);
     this.bgImageId       = result.Return(x => x.BackgroundImage.Return(i => i.Id, (Guid?)null), null);
     this.bgColor         = result.BackgroundColor;
     this.correctColor    = result.CorrectColor;
     this.hintColor       = result.HintColor;
     this.incorrectColor  = result.IncorrectColor;
     this.questionColor   = result.QuestionColor;
     this.selectionColor  = result.SelectionColor;
     this.titleColor      = result.TitleColor;
 }
Example #3
0
        /// <summary>
        /// The convert DTO and save.
        /// </summary>
        /// <param name="dto">
        /// The DTO.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <param name="flushUpdates">
        /// The flush Updates.
        /// </param>
        /// <returns>
        /// The <see cref="SubModuleItem"/>.
        /// </returns>
        public override SubModuleItem Convert(SubModuleItemDTO dto, SubModuleItem instance, bool flushUpdates = false)
        {
            instance          = instance ?? new SubModuleItem();
            instance.IsActive = dto.isActive;
            instance.IsShared = dto.isShared;
            if (instance.IsTransient())
            {
                instance.DateCreated = DateTime.Now;
            }

            instance.DateModified      = DateTime.Now;
            instance.SubModuleCategory = this.subModuleCategoryModel.GetOneById(dto.subModuleCategoryId).Value;
            instance.CreatedBy         = dto.createdBy.HasValue ? this.userModel.GetOneById(dto.createdBy.Value).Value : null;
            instance.ModifiedBy        = dto.modifiedBy.HasValue ? this.userModel.GetOneById(dto.modifiedBy.Value).Value : null;

            if (instance.IsTransient() || flushUpdates)
            {
                this.subModuleItemModel.RegisterSave(instance);
            }

            if (dto.themeVO != null)
            {
                SubModuleItemTheme    theme   = instance.Themes.FirstOrDefault() ?? new SubModuleItemTheme();
                SubModuleItemThemeDTO themeVo = dto.themeVO;
                theme.BackgroundColor  = themeVo.bgColor;
                theme.HintColor        = themeVo.hintColor;
                theme.CorrectColor     = themeVo.correctColor;
                theme.IncorrectColor   = themeVo.incorrectColor;
                theme.InstructionColor = themeVo.instructionColor;
                theme.QuestionColor    = themeVo.questionColor;
                theme.SelectionColor   = themeVo.selectionColor;
                theme.TitleColor       = themeVo.titleColor;
                theme.SubModuleItem    = instance;
                if (theme.IsTransient() || flushUpdates)
                {
                    this.subModuleItemThemeModel.RegisterSave(theme);
                }

                instance.Themes.Add(theme);
            }

            return(instance);
        }