Exemplo n.º 1
0
        public string UpdateArticle(VwArticle articleModel)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Article updateArticle = db.Articles.Where(a => a.Id.ToString() == articleModel.Id).FirstOrDefault();
                    updateArticle.Title          = articleModel.Title;
                    updateArticle.CategoryRef    = articleModel.CategoryRef;
                    updateArticle.SubCategoryRef = articleModel.SubCategoryRef;
                    updateArticle.ImageName      = articleModel.ImageName;
                    updateArticle.LastUpdated    = articleModel.LastUpdated; //DateTime.Now;
                    updateArticle.ByLineRef      = articleModel.ByLineRef;
                    updateArticle.Content        = articleModel.Content;
                    updateArticle.Summary        = articleModel.Summary;

                    //db.ArticleTags.RemoveRange(db.ArticleTags.Where(t => t.articleId.ToString() == editArticle.Id));
                    ////article.ArticleTags = null;
                    //foreach (DbArticleTagModel tagModel in editArticle.Tags)
                    //{
                    //    article.ArticleTags.Add(new ArticleTag() { articleId = article.Id, Id = tagModel.Id, TagName = tagModel.TagName });
                    //}

                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Exemplo n.º 2
0
        public ArticleModel GetSingleArticle(string articleId)
        {
            var articleModel = new ArticleModel();

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    VwArticle dbVwArticle = db.VwArticles.Where(a => a.Id.ToString() == articleId).FirstOrDefault();
                    if (dbVwArticle != null)
                    {
                        articleModel.Article = dbVwArticle;
                        articleModel.Success = "ok";
                    }
                }
            }
            catch (Exception ex) { articleModel.Success = Helpers.ErrorDetails(ex); }
            return(articleModel);
        }
Exemplo n.º 3
0
        public string AddNewArticle(VwArticle articleModel)
        {
            string success;

            try
            {
                Article newArticle = new Article
                {
                    //Id = Guid.NewGuid().ToString(),
                    Id             = articleModel.Id,
                    Title          = articleModel.Title,
                    CategoryRef    = articleModel.CategoryRef,
                    SubCategoryRef = articleModel.SubCategoryRef,
                    ImageName      = articleModel.ImageName,
                    Created        = DateTime.Now,
                    LastUpdated    = DateTime.Now,
                    Content        = articleModel.Content,
                    Summary        = articleModel.Summary,
                    ByLineRef      = articleModel.ByLineRef
                };

                //foreach (DbArticleTagModel tag in articleModel.Tags)
                //    if (tag.TagName != null)
                //        newArticle.ArticleTags.Add(new ArticleTag() { TagName = tag.TagName, TagCategoryRef = tag.TagCategoryRef });
                using (WebSiteContext db = new WebSiteContext())
                {
                    db.Articles.Add(newArticle);
                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }