public async Task <HttpResponseMessage> Get(byte id) { var result = await redisCache.GetAsync <FeatureViewModel>(id); if (result == null) { List <string> list = new List <string> { "Id" }; var para = APIProvider.APIDefaultParameter(list, id); var data = await _iFeatureRepo.SingleQuery(para); result = new FeatureViewModel { Id = data.Id, Title = data.Title, Image = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, data.Image), Description = data.Description, Handler = data.Handler, IsUsed = data.IsUsed }; // await redisCache.AddAsync <FeatureViewModel>(result); } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public async Task <IEnumerable <DepartmentViewModel> > Get() { try { var results = await redisCache.GetListAsync <DepartmentViewModel>(); if (results == null) { IList <string> list = new List <string> { "id" }; var para = APIProvider.APIDefaultParameter(list, 0); var data = await _department.Query(para); results = data.Select(s => new DepartmentViewModel() { Id = s.Id, Name = s.Name, Description = s.Description, Handler = s.Handler, Sort = s.Sort, Img = (s.Img != null ? LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.Internal, Path.Combine(ValueConstants.IMAGE_DEPARTMENT_PATH, s.Img)) : "") }).AsEnumerable(); // await redisCache.AddListAsync <DepartmentViewModel>(results); } return(results); } catch (Exception ex) { throw; } }
public async Task <HttpResponseMessage> GetCategoryChuyenKhoa(string handler, byte parentId) { var results = await redisCache.GetListAsync <CategoryViewModel>("Handler", handler, "ParentId", parentId); try { if (results == null || results.Count() == 0) { IList <string> list = new List <string> { "Handler", "ParentId" }; var para = APIProvider.APIDefaultParameter(list, handler, parentId); var source = await _iCategoryRepo.QueryPostCategoryDept(para); var dest = source.Select(x => new CategoryViewModel() { Id = x.Id, Name = x.Name, Handler = x.Handler, Image = (x.Image != null ? LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, Path.Combine(string.Empty, x.Image)) : ""), Sort = x.Sort, ParentId = x.ParentId }).AsEnumerable(); //List<CategoryViewModel> dest = Mapper.Map<List<CategoryViewModel>>(source); //await redisCache.AddListAsync<CategoryViewModel>(dest, "Handler", "Id", "ParentId"); return(Request.CreateResponse(HttpStatusCode.OK, dest)); } results = results.Where(x => x.ParentId == parentId); } catch (Exception ex) { throw; } return(Request.CreateResponse(HttpStatusCode.OK, results)); }
public async Task <DepartmentViewModel> Get(short id) { try { var result = await redisCache.GetAsync <DepartmentViewModel>(id); if (result == null) { IList <string> list = new List <string> { "id" }; var para = APIProvider.APIDefaultParameter(list, id); var data = await _department.SingleQuery(para); result = new DepartmentViewModel(); result.Id = data.Id; result.Name = data.Name; result.Description = data.Description; result.Handler = data.Handler; if (data.Img != null) { result.Img = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.Internal, Path.Combine(ValueConstants.IMAGE_DEPARTMENT_PATH, data.Img)); } result.Sort = data.Sort; } return(result); } catch (Exception ex) { throw; } }
public async Task <GalleryViewModel> Get(string id) { var result = await redisCache.GetAsync <GalleryViewModel>("DepartmentId"); if (result == null) { IList <string> list = new List <string> { "Id", "DepartmentId" }; var para = APIProvider.APIDefaultParameter(list, id, 0); var source = await _iGalleryRepo.Get(para); result = new GalleryViewModel(); if (source != null) { result.Id = source.Id; result.Title = source.Title; result.Description = source.Description; result.Highlight = source.Highlight; result.Img = source.Img != null?LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, result.Img) : null; result.YoutubeURL = source.YoutubeURL; result.Date = source.Date; result.DepartmentId = source.DepartmentId; result.IsMultiple = source.IsMultiple; } } return(result); }
public async Task <HttpResponseMessage> Get() { try { var results = await redisCache.GetListAsync <SliderViewModel>(); if (results == null || results.Count() == 0) { var data = await _iSliderRepo.GetAll(); results = data.Select(s => new SliderViewModel() { Id = s.Id, Title = s.Title, Description = s.Description, Image = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, s.Image) }).AsEnumerable(); // await redisCache.AddListAsync(results); } return(Request.CreateResponse(HttpStatusCode.OK, results)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public HttpResponseMessage Get() { try { var results = redisCache.GetList <AdvertiseViewModel>(); if (results == null) { var data = _iAdvertiseRepo.GetAll(); if (data != null && data.Count > 0) { results = data.Select(s => new AdvertiseViewModel() { Id = s.Id, Name = s.Name, Resouce = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, s.Resouce), Handler = s.Handler, Type = s.Type, StartDate = s.StartDate, EndDate = s.EndDate, Image = (s.Type > 0 ? LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, s.Resouce.Split('.')[0]) : s.Resouce) }).AsEnumerable(); } redisCache.AddList <AdvertiseViewModel>(results); //foreach (var item in data) //{ // var advertise = new AdvertiseViewModel(); // advertise.Id = item.Id; // advertise.Name = item.Name; // advertise.Resouce = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, item.Resouce); // advertise.Handler = item.Handler; // advertise.Type = item.Type; // advertise.StartDate = item.StartDate; // advertise.EndDate = item.EndDate; // if (item.Type > 0) // { // advertise.Image = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, item.Resouce.Split('.')[0]); // } // else // { // advertise.Image = advertise.Resouce; // } // results.Add(advertise); //} } return(Request.CreateResponse(HttpStatusCode.OK, results)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <IEnumerable <GalleryViewModel> > Query(byte departmentId = 0) { try { var results = await redisCache.GetListAsync <GalleryViewModel>("DepartmentId"); if (results == null) { List <string> list = new List <string> { "Id", "DepartmentId" }; Dictionary <string, dynamic> para = APIProvider.APIDefaultParameter(list, null, departmentId); var source = await _iGalleryRepo.Query(para); results = source.Select(s => new GalleryViewModel() { Id = s.Id, Title = s.Title, Description = s.Description, Highlight = s.Highlight, Img = s.Img != null ? LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, s.Img) : null, YoutubeURL = s.YoutubeURL, Date = s.Date, DepartmentId = s.DepartmentId, IsMultiple = s.IsMultiple }).AsEnumerable(); // await redisCache.AddListAsync <GalleryViewModel>(results, "DepartmentId", "Id"); await redisCache.AddListAsync <GalleryViewModel>(results); } //List<GalleryViewModel> dest = Mapper.Map<List<GalleryViewModel>>(source); return(results); } catch (Exception ex) { throw ex; } }
public async Task <HttpResponseMessage> Get() { try { var results = await redisCache.GetListAsync <FeatureViewModel>(); if (results == null || results.Count() == 0) { List <string> list = new List <string> { "Id" }; var para = APIProvider.APIDefaultParameter(list, 0); var data = await _iFeatureRepo.Query(para); var listFeatures = Mapper.Map <List <FeatureViewModel> >(data); results = data.Select(s => new FeatureViewModel() { Id = s.Id, Title = s.Title, Image = LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, s.Image), Description = s.Description, Handler = s.Handler, IsUsed = s.IsUsed }).AsEnumerable(); // await redisCache.AddListAsync <FeatureViewModel>(results); } return(Request.CreateResponse(HttpStatusCode.OK, results)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <HttpResponseMessage> GetPosts(int Id, string languageCode) { try { var result = new PostsViewModel(); List <string> list = new List <string> { "LanguageCode", "CategoryId", "numTop", "priority", "type" }; var para = APIProvider.APIDefaultParameter(list, languageCode, (int)CategoryId.Posts, NUM_TOP, POSTSORT_TYPE.NEW); var paraDetail = APIProvider.APIDefaultParameter(new List <string> { "id" }, Id); var detail = await _iPostRepo.SingleQuery(paraDetail); detail.Image = detail.Image.Contains(ValueConstants.IMAGE_DEFAULT) == true ? null : LayoutGuide.SPA_ResourcePath(Provider.Common.APIEnums.Application.CMS, detail.Image); var listPost = await _iPostRepo.Query(para); result.lstPostListViewModel = Mapper.Map <List <PostListViewModel> >(listPost); result.PostViewModel = Mapper.Map <PostViewModel>(detail); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }