Пример #1
0
        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;
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        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));
            }
        }
Пример #7
0
        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));
            }
        }
Пример #8
0
        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;
            }
        }
Пример #9
0
        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));
            }
        }
Пример #10
0
        public async Task <ActionResult> Create(SliderViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (fileUpload == null)
                {
                    ModelState.AddModelError("Image", "Vui lòng chọn hình");
                }
                if (ModelState.IsValid)
                {
                    if (fileUpload != null)
                    {
                        model.Image = fileUpload.FileName;
                        string imgName = "";

                        int[] demiSize = LayoutGuide.GetDefaultSize(Image_ModuleName.Slider);
                        if (demiSize == null)
                        {
                            FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_SLIDER_PATH, ref imgName);
                        }
                        else
                        {
                            FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_SLIDER_PATH, ref imgName, demiSize[0], demiSize[1]);
                        }

                        model.Image = imgName;
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <SliderViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.Insert);

                    if (result)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var slider = new SliderModel();
                    if (TempData["Data"] == null)
                    {
                        slider.lstSliderViewModel = await APIProvider.Authorize_Get <List <SliderViewModel> >(_userSession.BearerToken, controllerName, APIConstant.API_Resource_CMS, ARS.Get);
                    }
                    else
                    {
                        slider.lstSliderViewModel = (List <SliderViewModel>)TempData["Data"];
                    }

                    if (slider.lstSliderViewModel == null)
                    {
                        slider.lstSliderViewModel = ApplicationGenerator.GetObject <List <SliderViewModel> >();
                    }
                    slider.SliderViewModel = model;

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", slider));
                }
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
Пример #11
0
        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));
            }
        }