public ResponseInfoModel List([FromUri] GetCategoryListInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                int pageSize = _systemConfigurationService.GetPageSize();
                int limit    = pageSize;
                int offset   = pageSize * (input.PageIndex - 1);
                int total;
                List <ArticleCategory> categoryList = _articleCategoryService.GetPageList(limit, offset, out total, a => a.ParentID == input.ParentID &&
                                                                                          (string.IsNullOrEmpty((input.Keywords ?? "").Trim()) || a.Name.Contains((input.Keywords ?? "").Trim())), true, a => a.OrderID).ToList();
                var outputList = categoryList.MapTo <List <GetCategoryListOutput> >();
                json.Result = new PagingInfo()
                {
                    totalCount = total, pageCount = (int)Math.Ceiling((decimal)total / pageSize), pageSize = pageSize, list = outputList
                };;
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/category/list", LocalizationConst.QueryFail);
            }
            return(json);
        }
        //public ProgramTypeDto GetProgramTypeById(int pTypeId)
        //{
        //    var programType = _programTypeRepository
        //                            .GetAll()
        //                            .Where(p => p.Id == pTypeId).FirstOrDefault();
        //    var pType = ObjectMapper.Map<ProgramTypeDto>(programType);
        //    return pType;
        //}

        //public UserTypeDto GetUserTypeById(int uTypeId)
        //{
        //    var userType = _programTypeRepository
        //                            .GetAll()
        //                            .Where(p => p.Id == uTypeId).FirstOrDefault();
        //    var uType = ObjectMapper.Map<UserTypeDto>(userType);
        //    return uType;
        //}

        public async Task <ListResultDto <CategoryDto> > GetCategoryList(GetCategoryListInput input)
        {
            var categoryList = await _categoryRepository
                               .GetAll()
                               .Include(t => t.PList)
                               .Include(t => t.CBTContents)
                               .ToListAsync();

            var programList = await _programListRepository.GetAllListAsync();

            var cList = from cl in categoryList
                        join pl in programList on cl.ProgramListId equals pl.Id
                        join pcl in categoryList on cl.ParentId equals pcl.Id into pclE
                        from pcl in pclE.DefaultIfEmpty()
                        select new CategoryDto
            {
                CategoryId         = cl.Id,
                CategoryName       = cl.CategoryName.Substring(0, cl.CategoryName.Length > 20 ? 20 : cl.CategoryName.Length) + (cl.CategoryName.Length > 20 ? "..." : ""),
                Description        = cl.Description.Substring(0, cl.Description.Length > 20 ? 20 : cl.Description.Length) + (cl.Description.Length > 20 ? "..." : ""),
                ParentId           = pcl?.Id,
                ParentCategoryName = pcl?.CategoryName,
                ProgramListId      = cl.ProgramListId,
                ProgramCode        = pl.UniqueId
            };

            return(new ListResultDto <CategoryDto>(
                       ObjectMapper.Map <List <CategoryDto> >(cList)
                       ));
        }
Beispiel #3
0
        public async Task <ActionResult> CategoryList(GetCategoryListInput input)
        {
            var output = await _eClassAppService.GetCategoryList(input);

            var model = new CategoryListViewModel(output.Items);

            return(View("CategoryList", model));
        }
        public async Task <ListResultDto <CategoryDto> > GetCategoryListByProgramId(GetCategoryListInput input)
        {
            try
            {
                var categoryList = await _categoryRepository
                                   .GetAll()
                                   .Include(t => t.PList)
                                   .Include(t => t.CBTContents)
                                   .Where(p => p.ProgramListId == input.ProgramListId)
                                   .ToListAsync();

                return(new ListResultDto <CategoryDto>(
                           ObjectMapper.Map <List <CategoryDto> >(categoryList)
                           ));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        // GET: /<controller>/
        public async Task <ActionResult> Index()
        {
            GetCategoryListInput input = new GetCategoryListInput();

            input.ProgramListId = 0;

            var output = await _eClassAppService.GetCategoryListByProgramId(input);

            //var program = _eClassAppService.GetProgramById(input.ProgramListId);

            //if (program != null)
            //{
            //    ViewBag.UniqueId = program.UniqueId;
            //    ViewBag.Name = program.Name;
            //    ViewBag.Description = program.Description;
            //}

            //List<CBTContentDto> cbtContentList = new List<CBTContentDto>();

            //foreach (var cat in output.Items)
            //{
            //    var contentByCategoryId = await _eClassAppService.GetCBTContentByCategoryId(cat.Id);
            //    cbtContentList.AddRange(contentByCategoryId);
            //}
            //cbtContentList = cbtContentList.ToList();

            var programSelectListItems = (await _eClassAppService.GeProgramDDLItems()).Items
                                         .Select(p => p.ToSelectListItem())
                                         .ToList();

            programSelectListItems.Insert(0, new SelectListItem {
                Value = string.Empty, Text = L("DEFAULTSELECT"), Selected = true
            });

            CategoryListViewModel clVM = new CategoryListViewModel(output.Items);

            //clVM.CBTContentLists = cbtContentList;
            clVM.ProgramList = programSelectListItems;

            return(View("PreviewCBT", clVM));
        }
        public async Task <PartialViewResult> GetContentDetail(int programId)
        {
            string viewName            = "PreviewDetail";
            GetCategoryListInput input = new GetCategoryListInput();

            input.ProgramListId = programId;

            var output = await _eClassAppService.GetCategoryListByProgramId(input);

            var program = _eClassAppService.GetProgramById(input.ProgramListId);

            if (program != null)
            {
                ViewBag.UniqueId    = program.UniqueId;
                ViewBag.Name        = program.Name;
                ViewBag.Description = program.Description;

                if (program.ProgramTypeId == 1)
                {
                    ViewBag.ProgramType = "Training";
                }
                else if (program.ProgramTypeId == 2)
                {
                    ViewBag.ProgramType = "Survey";
                }
            }

            if (program.ProgramTypeId == 1)
            {
                viewName = "PreviewTraining";
            }
            else if (program.ProgramTypeId == 2)
            {
                viewName = "PreviewDetail";
            }

            List <CBTContentDto> cbtContentList = new List <CBTContentDto>();

            foreach (var cat in output.Items)
            {
                var contentByCategoryId = await _eClassAppService.GetCBTContentByCategoryId(cat.Id);

                cbtContentList.AddRange(contentByCategoryId);
            }
            cbtContentList = cbtContentList.ToList();

            var programSelectListItems = (await _eClassAppService.GeProgramDDLItems()).Items
                                         .Select(p => p.ToSelectListItem())
                                         .ToList();

            programSelectListItems.Insert(0, new SelectListItem {
                Value = string.Empty, Text = L("DEFAULTSELECT"), Selected = true
            });

            CategoryListViewModel clVM = new CategoryListViewModel(output.Items);

            clVM.CBTContentLists = cbtContentList;
            clVM.ProgramList     = programSelectListItems;
            clVM.ProgramListId   = programId;

            return(PartialView(viewName, clVM));
        }