/// <summary>
        /// Updates an existing article
        /// </summary>
        public static bool UpdateArticle(int id, int categoryID, string title,
                                         string Abstract, string body, string country, string state, string city,
                                         DateTime releaseDate, DateTime expireDate, bool approved, bool listed,
                                         bool commentsEnabled, bool onlyForMembers)
        {
            title    = BizObject.ConvertNullToEmptyString(title);
            Abstract = BizObject.ConvertNullToEmptyString(Abstract);
            body     = BizObject.ConvertNullToEmptyString(body);
            country  = BizObject.ConvertNullToEmptyString(country);
            state    = BizObject.ConvertNullToEmptyString(state);
            city     = BizObject.ConvertNullToEmptyString(city);

            if (releaseDate == DateTime.MinValue)
            {
                releaseDate = DateTime.Now;
            }
            if (expireDate == DateTime.MinValue)
            {
                expireDate = DateTime.MaxValue;
            }

            ArticleDetails record = new ArticleDetails(id, DateTime.Now, "", categoryID,
                                                       "", title, Abstract, body, country, state, city, releaseDate, expireDate,
                                                       approved, listed, commentsEnabled, onlyForMembers, 0, 0, 0);
            bool ret = SiteProvider.Articles.UpdateArticle(record);

            BizObject.PurgeCacheItems("articles_article_" + id.ToString());
            BizObject.PurgeCacheItems("articles_articles");
            return(ret);
        }
        // GET: Articles/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArticleDetails artDet = new ArticleDetails();

            artDet.Article = db.Articles.Find(id);
            List <Comment> comments = new List <Comment>();

            if (artDet.Article == null)
            {
                return(HttpNotFound());
            }
            foreach (var comment in db.Comments)
            {
                if (comment.ArticleId == id)
                {
                    comments.Add(comment);
                }
            }
            artDet.Comments = comments;
            return(View(artDet));
        }
        public async Task <ArticleDetails> GetArticleDetailsAsync(string articleId, string currentUserId)
        {
            return(await Task.Run(async() => {
                var article = articles.FirstOrDefault(x => x.Id == articleId);
                if (article == null)
                {
                    return null;
                }
                article.Views++;

                var articleDetails = new ArticleDetails()
                {
                    Title = article.Title,
                    Abstract = article.Abstract,
                    Content = article.Content,
                    CreatedOn = article.CreatedOn,
                    UpdatedOn = article.UpdatedOn,
                    Id = article.Id,
                    Views = article.Views,
                    IsApproved = article.IsApproved,
                    IsPrivate = article.IsPrivate,
                    Author = await GetUserAsync(article.AuthorId),
                    CommentsCount = GetCommentsAsync(articleId).Result.Count
                };

                return articleDetails;
            }));
        }
Exemple #4
0
 /// <summary>
 /// Updates an article
 /// </summary>
 public override bool UpdateArticle(ArticleDetails article)
 {
     using (SqlConnection cn = new SqlConnection(this.ConnectionString))
     {
         SqlCommand cmd = new SqlCommand("tbh_Articles_UpdateArticle", cn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@ArticleID", SqlDbType.Int).Value        = article.ID;
         cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value       = article.CategoryID;
         cmd.Parameters.Add("@Title", SqlDbType.NVarChar).Value       = article.Title;
         cmd.Parameters.Add("@Abstract", SqlDbType.NVarChar).Value    = article.Abstract;
         cmd.Parameters.Add("@Body", SqlDbType.NText).Value           = article.Body;
         cmd.Parameters.Add("@Country", SqlDbType.NVarChar).Value     = article.Country;
         cmd.Parameters.Add("@State", SqlDbType.NVarChar).Value       = article.State;
         cmd.Parameters.Add("@City", SqlDbType.NVarChar).Value        = article.City;
         cmd.Parameters.Add("@ReleaseDate", SqlDbType.DateTime).Value = article.ReleaseDate;
         cmd.Parameters.Add("@ExpireDate", SqlDbType.DateTime).Value  = article.ExpireDate;
         cmd.Parameters.Add("@Approved", SqlDbType.Bit).Value         = article.Approved;
         cmd.Parameters.Add("@Listed", SqlDbType.Bit).Value           = article.Listed;
         cmd.Parameters.Add("@CommentsEnabled", SqlDbType.Bit).Value  = article.CommentsEnabled;
         cmd.Parameters.Add("@OnlyForMembers", SqlDbType.Bit).Value   = article.OnlyForMembers;
         cn.Open();
         int ret = ExecuteNonQuery(cmd);
         return(ret == 1);
     }
 }
        public ActionResult AddComment([FromBody] ArticleDetails articleDetails)
        {
            detailsRepository.Insert(articleDetails);
            detailsRepository.Save();

            return(Ok());
        }
        private void ArticlesList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var            article   = (ArticleDTO)ArticlesList.SelectedItem;
            ArticleDetails newWindow = new ArticleDetails(article);

            newWindow.ShowDialog();
        }
Exemple #7
0
 private void ArticlesList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (ArticlesList.SelectedItem != null)
     {
         ArticleDetails newWindow = new ArticleDetails((ArticleDTO)ArticlesList.SelectedItem);
         newWindow.ShowDialog();
     }
 }
Exemple #8
0
        internal async Task RemoveArticleDetails(Guid id)
        {
            ArticleDetails artDeets = await GetArticleDetails(id) as ArticleDetails;

            CloudTable table = await GetTable(_articleDetailsTable);

            await table.ExecuteAsync(TableOperation.Delete(artDeets));
        }
Exemple #9
0
        internal async Task DeleteArticleFile(Guid id)
        {
            ArticleDetails TableEnt = await GetArticleDetails(id);

            CloudTable ArticleDetails = await GetTable(_articleDetailsTable);

            TableOperation deleteIt = TableOperation.Delete(TableEnt);
            await ArticleDetails.ExecuteAsync(deleteIt);
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var article = await articleCore.GetArticleByIdAsync(presentation.ArticleId);

            if (article != null)
            {
                ArticleDetails newWindow = new ArticleDetails(article);
                newWindow.ShowDialog();
            }
        }
        public HttpResponseMessage GetArticle(int id)
        {
            var article = this.repository.All().Where(x => x.Id == id).FirstOrDefault();

            if (article == null)
            {
                return this.Request.CreateErrorResponse(HttpStatusCode.NotFound, "Item not found!");
            }

            var articleModel = new ArticleDetails(article);

            return this.Request.CreateResponse(HttpStatusCode.OK, articleModel);
        }
Exemple #12
0
 public ActionResult SaveArticle(ArticleDetails ArticleDetails)
 {
     if (ModelState.IsValid)
     {
         EntityRepository.SaveArticle(ArticleDetails);
         TempData["message"] = string.Format("Article has been saved");
         return(RedirectToAction("List", new { type = "Article" }));
     }
     else
     {
         return(RedirectToAction("List", new { type = "Article" }));
     }
 }
        public ActionResult UpdateDetails([FromBody] ArticleDetails articleDetails)
        {
            var article = detailsRepository.SelectById(articleDetails.ArticleId);

            if (article == null)
            {
                return(BadRequest("Not valid article id. Id:" + articleDetails.ArticleId));
            }

            detailsRepository.Update(articleDetails);
            detailsRepository.Save();

            return(Ok());
        }
Exemple #14
0
        private async void EditArticles_Click(object sender, RoutedEventArgs e)
        {
            if (ArticleDataGrid.SelectedIndex >= 0)
            {
                var article = await articleCore.GetArticleByIdAsync(((ArticleDTO)ArticleDataGrid.SelectedItem).ArticleId);

                ArticleDetails newArticleDetailsWindow = new ArticleDetails(article);
                newArticleDetailsWindow.ShowDialog();
            }
            else
            {
                MessageBox.Show("Choose article first");
            }
        }
        public IEnumerable<ArticleDetails> GetAllArticles()
        {
            var data = this.repository.All();

            List<ArticleDetails> articles = new List<ArticleDetails>();

            foreach (var article in data)
            {
                var newArticleDetails = new ArticleDetails(article);

                articles.Add(newArticleDetails);
            }

            return articles;
        }
 /// <summary>
 /// Returns a Article object filled with the data taken from the input ArticleDetails
 /// </summary>
 private static Article GetArticleFromArticleDetails(ArticleDetails record)
 {
     if (record == null)
     {
         return(null);
     }
     else
     {
         return(new Article(record.ID, record.AddedDate, record.AddedBy,
                            record.CategoryID, record.CategoryTitle, record.Title, record.Abstract, record.Body,
                            record.Country, record.State, record.City, record.ReleaseDate, record.ExpireDate,
                            record.Approved, record.Listed, record.CommentsEnabled, record.OnlyForMembers,
                            record.ViewCount, record.Votes, record.TotalRating));
     }
 }
Exemple #17
0
        private async Task <IClientArticle> InsertArticle(IClientArticle article, Guid Id)
        {
            // Turn the basic article into a Json blob
            var articleData = new ArticleFileData(article, Id);
            // Then store the info in table
            var articleDetails    = new ArticleDetails(article, Id);
            var articleBlobString = JsonConvert.SerializeObject(articleData);

            var articleDetailsTable = await articleDetailsStorage.Value;
            var articleBlobStore    = await articleBlobStorage.Value;
            await articleDetailsTable.Insert(articleDetails);

            await articleDetailsTable.Insert(new ArticleDetailsUrlId(articleDetails.Url, articleDetails.Id));

            await articleBlobStore.AddNewStringFile(articleBlobString, $"{Id}.json");

            return(new CompleteArticle(article, Id));
        }
Exemple #18
0
        public void SaveArticle(ArticleDetails articlesDetails)
        {
            Article dbArticle = context.Article.Find(articlesDetails.ArticleId);

            if (dbArticle != null)
            {
                dbArticle.Title            = articlesDetails.Title;
                dbArticle.ShortDescription = articlesDetails.ShortDescription;
                dbArticle.Description      = articlesDetails.Description;
                dbArticle.ReadTime         = articlesDetails.ReadTime;
                dbArticle.Tags             = articlesDetails.Tags;
                dbArticle.ImagePath        = articlesDetails.ImagePath;
                dbArticle.Enabled          = articlesDetails.Enabled;
                dbArticle.Rating           = articlesDetails.Rating;
                dbArticle.SEOId            = context.SEO.Where(c => c.MetaTagTitle == articlesDetails.SelectedMetaTagTitle).Select(c => c.SEOId).FirstOrDefault();
                dbArticle.ProductGameId    = context.ProductGame.Where(c => c.GameName == articlesDetails.SelectedGame).Select(c => c.ProductGameId).FirstOrDefault();
            }
            else
            {
                Article article = new Article
                {
                    ArticleId        = Guid.NewGuid(),
                    Title            = articlesDetails.Title,
                    ShortDescription = articlesDetails.ShortDescription,
                    Description      = articlesDetails.Description,
                    ReadTime         = articlesDetails.ReadTime,
                    Tags             = articlesDetails.Tags,
                    ImagePath        = articlesDetails.ImagePath,
                    Enabled          = articlesDetails.Enabled,
                    Rating           = articlesDetails.Rating,
                    ArticlePostTime  = DateTime.Now,
                    SEOId            = context.SEO.Where(c => c.MetaTagTitle == articlesDetails.SelectedMetaTagTitle).Select(c => c.SEOId).FirstOrDefault(),
                    ProductGameId    = context.ProductGame.Where(c => c.GameName == articlesDetails.SelectedGame).Select(c => c.ProductGameId).FirstOrDefault()
                };

                context.Article.Add(article);
            }

            context.SaveChanges();
        }
Exemple #19
0
        public void Get_WhenFound_ReturnsArticleDetails()
        {
            // arrange
            const int ARTICLE_ID      = 123;
            var       expectedDetails = new ArticleDetails
            {
                Id = ARTICLE_ID
            };

            _mockArticleRepository.Setup(r => r.Fetch(It.IsAny <long>())).Returns(expectedDetails);

            // act
            var result = _articlesController.Get(ARTICLE_ID);

            // assert
            Assert.IsInstanceOfType(result, typeof(JsonResult));
            var jsonResult = (JsonResult)result;

            Assert.IsInstanceOfType(jsonResult.Value, typeof(ArticleDetails));
            var actualDetails = (ArticleDetails)jsonResult.Value;

            Assert.AreEqual(ARTICLE_ID, actualDetails.Id);
        }
        /// <summary>
        /// Creates a new article
        /// </summary>
        public static int InsertArticle(int categoryID, string title, string Abstract,
                                        string body, string country, string state, string city, DateTime releaseDate, DateTime expireDate,
                                        bool approved, bool listed, bool commentsEnabled, bool onlyForMembers)
        {
            // ensure that the "approved" option is false if the current user is not
            // an administrator or a editor (it may be a contributor for example)
            bool canApprove = (BizObject.CurrentUser.IsInRole("Administrators") || BizObject.CurrentUser.IsInRole("Editors"));

            if (!canApprove)
            {
                approved = false;
            }

            title    = BizObject.ConvertNullToEmptyString(title);
            Abstract = BizObject.ConvertNullToEmptyString(Abstract);
            body     = BizObject.ConvertNullToEmptyString(body);
            country  = BizObject.ConvertNullToEmptyString(country);
            state    = BizObject.ConvertNullToEmptyString(state);
            city     = BizObject.ConvertNullToEmptyString(city);

            if (releaseDate == DateTime.MinValue)
            {
                releaseDate = DateTime.Now;
            }
            if (expireDate == DateTime.MinValue)
            {
                expireDate = DateTime.MaxValue;
            }

            ArticleDetails record = new ArticleDetails(0, DateTime.Now, BizObject.CurrentUserName,
                                                       categoryID, "", title, Abstract, body, country, state, city, releaseDate, expireDate,
                                                       approved, listed, commentsEnabled, onlyForMembers, 0, 0, 0);
            int ret = SiteProvider.Articles.InsertArticle(record);

            BizObject.PurgeCacheItems("articles_article");
            return(ret);
        }
Exemple #21
0
        public async Task <ArticleSearchPagingResult> SearchArticlesAsyc(ArticleSearchPagingOption options)
        {
            // Start with the articles collection
            var query = articles.AsQueryable();

            // filter the search key
            if (!string.IsNullOrEmpty(options.SearchKey))
            {
                query = query.Where(x => x.Content.ToLower().Contains(options.SearchKey.ToLower()) ||
                                    x.Title.ToLower().Contains(options.SearchKey.ToLower()));
            }

            // Join the needed collections
            var joinedQuery = GenerateArticleDetailsQuery(query, options.ProfilerId);

            switch (options.Filter)
            {
            case ArticleFilterEnum.MyArticles:
                joinedQuery = joinedQuery.Where(x => x.Author.Id == options.ProfilerId);
                break;

            case ArticleFilterEnum.MyLikes:
                joinedQuery = joinedQuery.Where(x => x.Rankings.Any(x => x.DidILike == true && x.UserId == options.ProfilerId));
                break;

            case ArticleFilterEnum.MyFavorites:
                joinedQuery = joinedQuery.Where(x => x.Rankings.Any(x => x.DidIFavor == true && x.UserId == options.ProfilerId));
                break;
            }

            switch (options.SortBy)
            {
            case SortByEnum.UpdatedOn:
                if (options.SortOrder == SortOrderEnum.Ascending)
                {
                    joinedQuery = joinedQuery.OrderBy(x => x.UpdatedOn);
                }
                else
                {
                    joinedQuery = joinedQuery.OrderByDescending(x => x.UpdatedOn);
                }
                break;

            case SortByEnum.Views:
                if (options.SortOrder == SortOrderEnum.Ascending)
                {
                    joinedQuery = joinedQuery.OrderBy(x => x.Views);
                }
                else
                {
                    joinedQuery = joinedQuery.OrderByDescending(x => x.Views);
                }
                break;

            case SortByEnum.Likes:
                if (options.SortOrder == SortOrderEnum.Ascending)
                {
                    joinedQuery = joinedQuery.OrderBy(x => x.Likes);
                }
                else
                {
                    joinedQuery = joinedQuery.OrderByDescending(x => x.Likes);
                }
                break;

            case SortByEnum.Favors:
                if (options.SortOrder == SortOrderEnum.Ascending)
                {
                    joinedQuery = joinedQuery.OrderBy(x => x.Favors);
                }
                else
                {
                    joinedQuery = joinedQuery.OrderByDescending(x => x.Favors);
                }
                break;
            }

            var docsCount = await joinedQuery.CountAsync();

            var documents = await joinedQuery.Skip((options.CurrentPage - 1) *options.PageSize).Take(options.PageSize).ToListAsync();

            var articleDetailsList = new List <ArticleDetails>();

            foreach (var item in documents)
            {
                item.Content = null; // Don't return the content
                var articleDetails = new ArticleDetails()
                {
                    Id            = item.Id,
                    Title         = item.Title,
                    Abstract      = item.Abstract,
                    UpdatedOn     = item.UpdatedOn,
                    CreatedOn     = item.CreatedOn,
                    IsApproved    = item.IsApproved,
                    IsPrivate     = item.IsPrivate,
                    Views         = item.Views,
                    Content       = item.Content,
                    Categories    = item.Categories,
                    GalleryImages = item.GalleryImages,
                    Author        = item.Author,
                    CommentsCount = item.CommentsCount,

                    Ranking = new ArticleRankingDetails(item.Id, options.ProfilerId, item.Rankings)
                };
                articleDetailsList.Add(articleDetails);
            }

            return(new ArticleSearchPagingResult(articleDetailsList, docsCount, options));
        }
 /// <summary>
 /// Updates an article
 /// </summary>
 public override bool UpdateArticle(ArticleDetails article)
 {
     using (SqlConnection cn = new SqlConnection(this.ConnectionString))
      {
     SqlCommand cmd = new SqlCommand("tbh_Articles_UpdateArticle", cn);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@ArticleID", SqlDbType.Int).Value = article.ID;
     cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = article.CategoryID;
     cmd.Parameters.Add("@Title", SqlDbType.NVarChar).Value = article.Title;
     cmd.Parameters.Add("@Abstract", SqlDbType.NVarChar).Value = article.Abstract;
     cmd.Parameters.Add("@Body", SqlDbType.NText).Value = article.Body;
     cmd.Parameters.Add("@Country", SqlDbType.NVarChar).Value = article.Country;
     cmd.Parameters.Add("@State", SqlDbType.NVarChar).Value = article.State;
     cmd.Parameters.Add("@City", SqlDbType.NVarChar).Value = article.City;
     cmd.Parameters.Add("@ReleaseDate", SqlDbType.DateTime).Value = article.ReleaseDate;
     cmd.Parameters.Add("@ExpireDate", SqlDbType.DateTime).Value = article.ExpireDate;
     cmd.Parameters.Add("@Approved", SqlDbType.Bit).Value = article.Approved;
     cmd.Parameters.Add("@Listed", SqlDbType.Bit).Value = article.Listed;
     cmd.Parameters.Add("@CommentsEnabled", SqlDbType.Bit).Value = article.CommentsEnabled;
     cmd.Parameters.Add("@OnlyForMembers", SqlDbType.Bit).Value = article.OnlyForMembers;
     cn.Open();
     int ret = ExecuteNonQuery(cmd);
     return (ret == 1);
      }
 }
        private async Task DeleteArticleFromUserAsync(ArticleDetails article)
        {
            var user = await this.GetUserAsync(article.AuthorId);

            await this.userService.DeleteArticlesFromUserAsync(user, new string[] { article.Id });
        }