public static string GenerateBodyHtml(Post post)
        {
            var title = "|*TITLE*|";
            var urlImgSocialNetwork = "|*URL_IMG_SOCIAL_NETWORK*|";
            var urlImgSentiment = "|*URL_IMG_SENTIMENT*|";
            var urlPost = "|*URL_POST*|";
            var date = "|*DATE*|";
            var content = "|*CONTENT*|";
            var urlImgUserProfile = "|*URL_IMG_USER_PROFILE*|";
            var urlProfile = "|*URL_PROFILE*|";
            var userName = "******";
            // Read the file as one string.
            var path = HttpContext.Current.Server.MapPath("../Content/template.html");
            var templateFile = new StreamReader(path);
            var bodyHtml = templateFile.ReadToEnd();

            templateFile.Close();

            bodyHtml = bodyHtml.Replace(title, "Post Enviado para revision.");
            bodyHtml = bodyHtml.Replace(urlImgSentiment, post.UrlImgSentiment);
            bodyHtml = bodyHtml.Replace(urlImgSocialNetwork, post.UrlImgNetwork);
            bodyHtml = bodyHtml.Replace(urlPost, post.UrlPost);
            bodyHtml = bodyHtml.Replace(date, post.CreatedAtShort);
            bodyHtml = bodyHtml.Replace(urlImgUserProfile, post.ProfileImage);
            bodyHtml = bodyHtml.Replace(urlProfile, post.UrlProfile);
            bodyHtml = bodyHtml.Replace(userName, post.UserName);

            var postContent = post.Content.Length > 150 ? post.Content.Substring(0, 150) + "..." : post.Content;
            bodyHtml = bodyHtml.Replace(content, postContent);

            return bodyHtml;
        }
        public void ProcessItem(Post item)
        {
            string content = item.Content.ToLower();
            foreach (var ignoreChar in IgnoreChars)
            {
                content = content.Replace(ignoreChar, " ");
            }
            var cantNeg = NegativeWords.Count(word => content.Contains(" " + word + " "));
            var cantPos = PositiveWords.Count(word => content.Contains(word));

            item.Sentiment = SentimentNeutral;
            if (cantNeg > 0)
            {
                item.Sentiment = SentimentNegative;
            }
            if (cantPos > 0)
            {
                item.Sentiment = SentimentPositive;
            }
            if (cantNeg > 0 && cantPos > 0) item.Sentiment = SentimentNeutral;

            if (item.Sentiment == SentimentNegative) _negativeCount++;
            if (item.Sentiment == SentimentPositive) _positiveCount++;
            if (item.Sentiment == SentimentNeutral) _neutralCount++;
        }
 public void ProcessItem(Post item)
 {
     if (string.IsNullOrWhiteSpace(item.UserName)) return;
     if (!_engines.ContainsKey(item.UserName))
     {
         _engines.Add(item.UserName, new Engine() { Name = item.UserName });
     }
     _engines[item.UserName].Counter++;
 }
        public void Process1ItemShouldIncrementCounterTest()
        {
            //arrange
            SearchEngineBoxBuilder builder = new SearchEngineBoxBuilder();
            var item1 = new Post(){SocialNetworkName = "Twitter"};
            //act
            builder.ProcessItem(item1);

            //assert
            builder.Engines.Count.Should().Be.EqualTo(1);
            builder.Engines[0].Name.Should().Be.EqualTo(item1.SocialNetworkName);
            builder.Engines[0].Counter.Should().Be.EqualTo(1);
        }
        public bool Edit(Post post)
        {
            var result = _posts.Collection.FindAndModify(
                Query.And(Query.EQ("_id", post.PostId), Query.EQ("Version", post.Version)),
                null,
                Update.Set("Title", post.Title)
                    .Set("Url", post.Url)
                    .Set("Summary", post.Summary)
                    .Set("Details", post.Details)
                    .Inc("Version", 1));

            return result.ModifiedDocument != null;
        }
        public ActionResult Create(Post post)
        {
            if (ModelState.IsValid)
            {
                post.Url = post.Title.GenerateSlug();
                post.Author = User.Identity.Name;
                post.Date = DateTime.Now;

                _postService.Create(post);

                return RedirectToAction("Index");
            }

            return View();
        }
        public ActionResult Update(Post post)
        {
            if (ModelState.IsValid)
            {
                post.Url = post.Title.GenerateSlug();

                if (_postService.Edit(post))
                {
                    return RedirectToAction("Index");    
                }

                ModelState.AddModelError("ConcurrencyError", "This post has been updated since you started editing it. Please reload the post to get the latest changes.");
                return View(post);
            }

            return View(post);
        }
        public void buildBoxWith2SearchEnginecon3y2ItemsTest()
        {
            //arrange
            SearchEngineBoxBuilder builder = new SearchEngineBoxBuilder();
            var model = new SearchResultModel();
            var item1 = new Post() { SocialNetworkName = "Twitter" };
            var item2 = new Post() { SocialNetworkName = "Twitter" };
            var item3 = new Post() { SocialNetworkName = "Twitter" };
            var item4 = new Post() { SocialNetworkName = "Facebook" };
            var item5 = new Post() { SocialNetworkName = "Facebook" };
            model.Items.AddRange(new List<Post>() { item1, item2, item3, item4, item5 });
            //act
            builder.BuildBox(model);

            //assert
            model.StatBoxs.Count.Should().Be.EqualTo(1);
            model.StatBoxs[0].StatItems.Count.Should().Be.EqualTo(2);
            model.StatBoxs[0].StatItems[0].Title.Should().Be.EqualTo("Twitter");
            model.StatBoxs[0].StatItems[1].Title.Should().Be.EqualTo("Facebook");
            model.StatBoxs[0].StatItems[0].ValueText.Should().Be.EqualTo("60,00%");
            model.StatBoxs[0].StatItems[1].ValueText.Should().Be.EqualTo("40,00%");
        }
        public void Process2ItemFromFrom2EnginesShouldSetCounterTo2Test()
        {
            //arrange
            SearchEngineBoxBuilder builder = new SearchEngineBoxBuilder();
            var item1 = new Post() { SocialNetworkName = "Twitter" };
            var item2 = new Post() { SocialNetworkName = "Twitter" };
            var item3 = new Post() { SocialNetworkName = "Facebook" };
            var item4 = new Post() { SocialNetworkName = "Facebook" };
            //act
            builder.ProcessItem(item1);
            builder.ProcessItem(item2);
            builder.ProcessItem(item3);
            builder.ProcessItem(item4);

            //assert
            builder.Engines.Count.Should().Be.EqualTo(2);
            builder.Engines[0].Counter.Should().Be.EqualTo(2);
            builder.Engines[1].Counter.Should().Be.EqualTo(2);
        }
 public void Create(Post post)
 {
     post.Comments = new List<Comment>();
     _posts.Collection.Save(post);
 }
        private bool ValidateFilters(string sentiment, string socialNetworking, string userName, Post item)
        {
            bool functionValueReturn = (!string.IsNullOrEmpty(sentiment) && item.Sentiment.ToLower() == sentiment.ToLower()) ||
                                       (!string.IsNullOrEmpty(socialNetworking) && item.SocialNetworkName.ToLower() == socialNetworking.ToLower()) ||
                                       (!string.IsNullOrEmpty(userName) && item.UserName.ToLower() == userName.ToLower());

            return functionValueReturn;
        }
 public JsonResult TagPost(Post post, string tagName)
 {
     var servicesManager = new ServicesManager();
     return Json(servicesManager.TagPost(post, tagName), JsonRequestBehavior.AllowGet);
 }
        public void SendPostToMail(string to, string subject, string content, string urlPost, string createdAt, string usrName,
            string urlUser, string urlImgNetwork, string urlImgProfile, string urlImgSentiment)
        {
            var address = ConfigurationManager.AppSettings["addressFrom"];
            var displayName = ConfigurationManager.AppSettings["displayName"];
            var userName = ConfigurationManager.AppSettings["userName"];
            var password = ConfigurationManager.AppSettings["password"];
            var port = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
            var host = ConfigurationManager.AppSettings["host"];

            var post = new Post
                           {
                               Content = content,
                               UrlPost = urlPost,
                               UserName = usrName,
                               UrlProfile = urlUser,
                               ProfileImage = urlImgProfile,
                               UrlImgNetwork = urlImgNetwork,
                               UrlImgSentiment = urlImgSentiment

                           };
            var servicesManager = new ServicesManager();
            servicesManager.SendPostToMail(to, address, displayName, subject, userName, password, port, host, post);
        }
 public JsonResult SavePost(Post post)
 {
     var servicesManager = new ServicesManager();
     return Json(servicesManager.SavePost(post), JsonRequestBehavior.AllowGet);
 }