public ActionResult Create(TweetViewModel tweet)
        {
            if (this.ModelState.IsValid)
            {
                tweet.AuthorId = this.User.Identity.GetUserId();

                var newTweet = new Tweet {AuthorId = tweet.AuthorId, Text = tweet.Text};
                this.db.Tweets.Add(newTweet);
                this.db.SaveChanges();

                // Show Tweet to all followers
                var context = GlobalHost.ConnectionManager.GetHubContext<TweeterHub>();
                var usernames = this.UserProfile.Followers.Select(f => f.UserName).ToList();
                context.Clients.Users(usernames).showTweet(newTweet.Id);

                this.TempData["message"] = "Tweet added successfully.";
                this.TempData["isMessageSuccess"] = true;

                return this.RedirectToAction("Index", "Home");
            }

            this.TempData["message"] = "There are problem with tweet adding.";
            this.TempData["isMessageSuccess"] = false;

            this.ViewBag.AuthorId = new SelectList(this.db.Users, "Id", "FullName", tweet.AuthorId);
            return this.View("Tweet/_CreateTweetPartial", tweet);
        }
        public ActionResult TweetsDestroy([DataSourceRequest] DataSourceRequest request, TweetViewModel tweetToDelete)
        {
            if (tweetToDelete != null)
            {
                this.tweets.Destroy(tweetToDelete.Id);
            }

            return Json(new[] { tweetToDelete }.ToDataSourceResult(request, ModelState));
        }
Example #3
0
        public static TweetViewModel ConvertToViewModel(Tweet tweet)
        {
            var newTweet = new TweetViewModel
            {
                Id = tweet.Id,
                User_Id = tweet.User_Id,
                Body = tweet.Body,
                DateAdded = tweet.Date_time,
                AuthorId = tweet.User_Id
            };

            return newTweet;
        }
Example #4
0
        public static Tweet ConvertToDB(TweetViewModel tweet)
        {
            var newTweet = new Tweet
            {
                Id = tweet.Id,
                User = new User(),
                User_Id = tweet.User_Id,
                Body = tweet.Body,
                Date_time = DateTime.Now
            };

            return newTweet;
        }
Example #5
0
 public bool Update(TweetViewModel tweet)
 {
     bool result = false;
     try
     {
         result = tweetContext.Update(TweetConverter.ConvertToDB(tweet));
     }
     catch (Exception e)
     {
         Logger.Log.Error(e.Message);
     }
     return result;
 }
        public ActionResult TweetsUpdate([DataSourceRequest] DataSourceRequest request, TweetViewModel tweetToUpdate)
        {
            if (tweetToUpdate != null)
            {
                var tweet = new Tweet()
                {
                    Id = tweetToUpdate.Id,
                    Content = tweetToUpdate.Content,
                    CreatedOn = tweetToUpdate.CreatedOn,
                    ImageUrl = tweetToUpdate.ImageUrl
                };

                this.tweets.UpdateTweet(tweet);
            }

            return this.Json(new[] { tweetToUpdate }.ToDataSourceResult(request, this.ModelState));
        }
        public ActionResult Create(SubmitTweetViewModel model)
        {
            var tweetViewModel = new TweetViewModel();

            if (model != null && this.ModelState.IsValid)
            {
                var user = this.data
                    .Users
                    .GetById(this.User.Identity.GetUserId());

                var newTweet = new Tweet()
                {
                    Content = model.Content,
                    User = user,
                    CreationDate = DateTime.UtcNow
                };

                this.data.Tweets.Add(newTweet);
                this.data.SaveChanges();

                var hashTags = this.GetHashTags(model.Content);
                foreach (var hashTag in hashTags)
                {
                    var resultHashTag = this.CreateOrUpdateHashTag(hashTag);
                    newTweet.HashTags.Add(resultHashTag);
                    this.data.HashTags.Update(resultHashTag);
                }

                this.data.Tweets.Update(newTweet);
                this.data.SaveChanges();

                tweetViewModel.Content = newTweet.Content;
                tweetViewModel.CreationDate = newTweet.CreationDate;
                tweetViewModel.UserId = newTweet.UserId;
                tweetViewModel.Username = newTweet.User.UserName;
            }

            return PartialView("_Tweet", tweetViewModel);
        }