示例#1
0
        public IActionResult GetLanguagesList()
        {
            try
            {
                IList <LangViewModel> Langs = _langService.Queryable()
                                              .Select(x => Mapper.Map <LangViewModel>(x))
                                              .ToList();

                foreach (var lang in Langs)
                {
                    byte[] imageArray = System.IO.File.ReadAllBytes(@"" + _appEnvironment.WebRootPath + "/flags/" + lang.Image + ".png");
                    string base64ImageRepresentation = "data:image/png;base64," + Convert.ToBase64String(imageArray);
                    lang.Image = base64ImageRepresentation;
                }

                return(new JsonResult(
                           new
                {
                    code = EnumResponseStatus.SUCCESS,
                    data = Langs
                }
                           ));
            }
            catch (Exception ex)
            {
                return(new JsonResult(
                           new
                {
                    code = EnumResponseStatus.ERROR,
                    error_message_key = ex.Message
                }
                           ));
            }
        }
示例#2
0
        public IViewComponentResult Invoke()
        {
            var viewModel = new HeaderViewModel();
            var user      = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser");

            if (user != null)
            {
                viewModel.User = _sysUserService.Queryable().Where(x => x.Id == user.Id).Select(x => Mapper.Map <SysUserViewModel>(x)).FirstOrDefault();
            }
            else
            {
                viewModel.User = user;
            }

            viewModel.Langs = _langService.Queryable()
                              .Select(x => Mapper.Map <LangViewModel>(x))
                              .ToList();

            var langId = HttpContext.Session.GetInt32("LangId");

            if (HttpContext.Session.GetInt32("LangId").HasValue)
            {
                viewModel.Lang = viewModel.Langs.FirstOrDefault(x => x.Id == HttpContext.Session.GetInt32("LangId").Value);
            }
            else
            {
                viewModel.Lang = viewModel.Langs.FirstOrDefault(x => x.Id == (int)EnumLang.ENGLISH);
            }

            return(View(viewModel));
        }
示例#3
0
        public IViewComponentResult Invoke()
        {
            var viewModel = new FooterViewModel();

            viewModel.Langs = _langService.Queryable()
                              .Select(x => Mapper.Map <LangViewModel>(x))
                              .ToList();

            var langId = HttpContext.Session.GetInt32("LangId");

            if (HttpContext.Session.GetInt32("LangId").HasValue)
            {
                viewModel.Lang = viewModel.Langs.FirstOrDefault(x => x.Id == HttpContext.Session.GetInt32("LangId").Value);
            }
            else
            {
                viewModel.Lang = viewModel.Langs.FirstOrDefault(x => x.Id == (int)EnumLang.ENGLISH);
            }

            return(View(viewModel));
        }