Esempio n. 1
0
        public ArticleDetailModel GetArticleIntro()
        {
            var currentLanguage = _workContext.CurrentLanguage;
            var defaultLanguage = _resourceService.DefaultLanguageId();

            var articleLanguage = _articleLanguageRepository.Table.Where(p => p.Article.RootCate == (int)ERootCategory.Intro && p.Article.IsActive &&
                                                                         p.LanguageId == currentLanguage).Select(p => new ArticleDetailModel
            {
                Id       = p.ArticleId,
                HeadLine = p.HeadLine,
                Content  = p.Content,
                ImageId  = p.Article.FeatureImageId,
                Extract  = p.Extract,
            }).FirstOrDefault();

            if (articleLanguage == null && currentLanguage == defaultLanguage)
            {
                return(null);
            }
            articleLanguage = _articleLanguageRepository.Table.Where(p => p.Article.RootCate == (int)ERootCategory.Intro && p.Article.IsActive &&
                                                                     p.LanguageId == defaultLanguage
                                                                     ).Select(p => new ArticleDetailModel
            {
                Id       = p.ArticleId,
                HeadLine = p.HeadLine,
                Content  = p.Content,
                ImageId  = p.Article.FeatureImageId,
                Extract  = p.Extract,
            }).FirstOrDefault();
            if (articleLanguage == null)
            {
                return(null);
            }


            if (articleLanguage.ImageId.HasValue)
            {
                articleLanguage.UrlImage = _mediaService.GetPictureUrl(articleLanguage.ImageId.Value);
            }
            else
            {
                articleLanguage.UrlImage = "~/Content/images/no-image.png";
            }
            return(articleLanguage);
        }
Esempio n. 2
0
        public HttpResponseMessage Put(Article article)
        {
            //_articleRepository.Update(article);
            var entity = _articleRepository.Table.Where(p => p.Id == article.Id).Include(p => p.ArticleLanguages)
                         .Include("ArticleLanguages.MetaTag")
                         .FirstOrDefault();

            if (entity == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            entity.HeadLine       = article.ArticleLanguages.Where(p => p.LanguageId == _resourceService.DefaultLanguageId()).Select(p => p.HeadLine).FirstOrDefault();
            entity.ModifiedDate   = DateTimeHelper.GetCurrentDateTime();
            entity.IsActive       = article.IsActive;
            entity.IsShowHomepage = article.IsShowHomepage;
            entity.Section1       = article.Section1;
            entity.Section2       = article.Section2;
            if (article.FeatureImageId.HasValue && entity.FeatureImageId != article.FeatureImageId)
            {
                entity.FeatureImageId = article.FeatureImageId;
            }

            foreach (var entityArticleLanguage in entity.ArticleLanguages)
            {
                var obj = article.ArticleLanguages.FirstOrDefault(p => p.Id == entityArticleLanguage.Id);
                if (obj != null)
                {
                    entityArticleLanguage.HeadLine            = obj.HeadLine;
                    entityArticleLanguage.Content             = obj.Content;
                    entityArticleLanguage.Extract             = obj.Extract;
                    entityArticleLanguage.MetaTag.Description = obj.MetaTag.Description;
                    entityArticleLanguage.MetaTag.Keywords    = obj.MetaTag.Keywords;
                }
            }

            //entity.ArticleLanguages.
            article.ArticleLanguages.Where(p => p.Id == 0).ToList().ForEach(p =>
            {
                entity.ArticleLanguages.Add(p);
            });

            _articleRepository.Update(entity);
            _articleRepository.SaveChanges();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }