Пример #1
0
        public static ZenQuoteViewModel Convert(ZenQuote zenQuote, string language = "EN", IHostingEnvironment hostingEnvironment = null)
        {
            var message = zenQuote.ZenMessages.FirstOrDefault(o => o.Language.Code.Equals(language, StringComparison.OrdinalIgnoreCase));

            if (message == null)
            {
                return(null);
            }

            var z = new ZenQuoteViewModel
            {
                Id        = zenQuote.Id,
                Message   = message.Message,
                Author    = zenQuote.Author,
                Language  = message.Language.Code,
                CreatedOn = zenQuote.CreatedOn,
                Likes     = zenQuote.Likes,
                Dislikes  = zenQuote.Dislikes,
                Tags      = zenQuote.ZenQuoteTags?.Select(t => t.Tag.Name).ToList()
            };

            if (hostingEnvironment != null)
            {
                var img    = new ZenQuoteImage(z, hostingEnvironment).GetImage();
                var base64 = System.Convert.ToBase64String(ZenSourceUtil.ReadStream(img));
                z.Image64Encoded = base64;
            }

            return(z);
        }
Пример #2
0
        public IActionResult Images(string search, string ids, int?page, string l, string tags)
        {
            var tagsIds = new List <int>();

            if (tags != null)
            {
                tagsIds = tags.Split(',').Select(t => Convert.ToInt32(t)).ToList();
            }

            var quotesIds = new List <int>();

            if (ids != null)
            {
                quotesIds = ids.Split(',').Select(t => Convert.ToInt32(t)).ToList();
            }

            var modelList = _repository.GetAll(search, quotesIds, tagsIds, page, l, true);

            if (l == null)
            {
                l = "en";
            }

            var viewModelList = Mapper.Map <IEnumerable <ZenQuoteViewModel> >(modelList).Where(q => q.Language.Equals(l, StringComparison.OrdinalIgnoreCase)).ToList();

            foreach (var v in viewModelList)
            {
                var img    = new ZenQuoteImage(v, _hostingEnvironment).GetImage();
                var base64 = Convert.ToBase64String(ZenSourceUtil.ReadStream(img));
                v.Image64Encoded = base64;
            }

            return(Json(viewModelList));
        }