Пример #1
0
        public BaseResponse <IList <TsgCategory> > QueryTsgCategory(BaseRequest <TsgCategoryFilter> request)
        {
            BaseResponse <IList <TsgCategory> > response = new BaseResponse <IList <TsgCategory> >();

            Mapper.CreateMap <TSG_CATEGORY, TsgCategory>();
            var q = from m in unitOfWork.GetRepository <TSG_CATEGORY>().dbSet
                    select m;

            q = q.Where(m => m.STATUS == true);
            q = q.OrderBy(m => m.ID);
            List <TSG_CATEGORY> list = q.ToList();
            var data        = new List <TsgCategory>();
            var tsgCategory = new TsgCategory();

            foreach (var item in list)
            {
                tsgCategory.Id   = item.ID;
                tsgCategory.Code = item.CODE;
                tsgCategory.Name = item.NAME;
                data.Add(tsgCategory);
                tsgCategory = new TsgCategory();
            }
            response.Data = data;
            return(response);
        }
Пример #2
0
        public BaseResponse <IList <TsgCategory> > QueryTsgData(BaseRequest <TsgCategoryFilter> request)
        {
            BaseResponse <IList <TsgCategory> > response = new BaseResponse <IList <TsgCategory> >();

            Mapper.CreateMap <TSG_CATEGORY, TsgCategory>();
            Mapper.CreateMap <TSG_QUESTION, TsgQuestion>();
            Mapper.CreateMap <TSG_ANSWER, TsgAnswer>();
            var q = from m in unitOfWork.GetRepository <TSG_CATEGORY>().dbSet
                    select m;

            q = q.Where(m => m.STATUS == true);
            q = q.OrderBy(m => m.ID);
            List <TSG_CATEGORY> list = q.ToList();
            var data        = new List <TsgCategory>();
            var tsgCategory = new TsgCategory();

            tsgCategory.Class = "in active";
            foreach (var item in list)
            {
                tsgCategory.Id          = item.ID;
                tsgCategory.Code        = item.CODE;
                tsgCategory.Name        = item.NAME;
                tsgCategory.TsgQuestion = Mapper.Map <IList <TsgQuestion> >(item.TSG_QUESTION);
                foreach (var subItem in tsgCategory.TsgQuestion)
                {
                    foreach (var question in item.TSG_QUESTION)
                    {
                        if (subItem.Id == question.ID)
                        {
                            subItem.TsgAnswer = Mapper.Map <IList <TsgAnswer> >(question.TSG_ANSWER);
                        }
                    }
                }
                data.Add(tsgCategory);
                tsgCategory       = new TsgCategory();
                tsgCategory.Class = "";
            }

            response.Data = data;
            return(response);
        }