protected bool? GetUserVote(Article item)
        {
            string userID = this.User.Identity.GetUserId();
            var like = item.Likes.FirstOrDefault(l => l.UserID == userID);
            if (like == null)
            {
                return null;
            }

            return like.Value;
        }
 public void ArticlesListView_InsertItem()
 {
     var item = new Article();
     item.DateCreated = DateTime.Now;
     item.AuthorId = this.User.Identity.GetUserId();
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         db.Articles.Add(item);
         db.SaveChanges();
     }
 }
        public HttpResponseMessage PostArticles(ArticleModel model)
        {
            User author = userRepository.Get(model.AuthorId);

            var entityToAdd = new Article()
            {
                Title = model.Title,
                Content = model.Content,
                Author = author,
                //Images = model.Images,
                CreationDate = DateTime.Now,
                Image1 = model.Image1
            };

            var createEntity = this.articleRepository.Add(entityToAdd);

            author.Articles.Add(createEntity);

            this.userRepository.Update(author.UserId, author);

            var createdModel = new ArticleModel()
            {
                ArticleId = createEntity.ArticleId,
                Title = createEntity.Title,
                Content = createEntity.Content,
                CreationDate = createEntity.CreationDate,
                Rating = createEntity.Votes.Any() ? createEntity.Votes.Average(x=>x.Value) : 0,
                CommentsCount = createEntity.Comments.Count(),
                //Images = createEntity.Images
                Image1 = createEntity.Image1
            };

            PubnubAPI pubnub = new PubnubAPI(
                "pub-c-471827c9-62e3-42ac-8a02-524042ee4ba2",               // PUBLISH_KEY
                "sub-c-0cc9fc44-0531-11e3-a3d6-02ee2ddab7fe",               // SUBSCRIBE_KEY
                "sec-c-MGYwMDBlYjgtZmIxNC00N2Q0LThlNzgtZGVmZGMwNGE2YmJk",   // SECRET_KEY
                true                                                        // SSL_ON?
            );

            string channel = "newssytem-channel";
            string message = string.Format("{0} {1}", createdModel.Title, createdModel.CreationDate);
            pubnub.Publish(channel, message);

            var response = Request.CreateResponse<ArticleModel>(HttpStatusCode.Created, createdModel);
            var resourceLink = Url.Link("DefaultApi", new { ArticleId = createdModel.ArticleId });
            response.Headers.Location = new Uri(resourceLink);

            return response;
        }
 protected int GetLikesValue(Article item)
 {
     int likesCount = item.Likes.Count(l => l.Value == true);
     int hatesCount = item.Likes.Count(l => l.Value == false);
     return likesCount - hatesCount;
 }
Example #5
0
 public void FormViewIsertArticle_InsertItem()
 {
     var item = new Article();
     item.AuthorID = this.User.Identity.GetUserId();
     item.DateCreated = DateTime.Now;
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         this.dbContext.Articles.Add(item);
         this.dbContext.SaveChanges();
         ErrorSuccessNotifier.AddSuccessMessage("Article created!");
         ErrorSuccessNotifier.ShowAfterRedirect = true;
         Response.Redirect("~/Admin/Articles.aspx");
     }
 }