public ActionResult EditingInline_Create([DataSourceRequest] DataSourceRequest request, TweetInputModel tweetModel) { if (tweetModel != null && this.ModelState.IsValid) { var tweet = Mapper.Map<Tweet>(tweetModel); this.Data.Tweets.Add(tweet); this.Data.SaveChanges(); } return this.Json(new[] { tweetModel }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult EditingInline_Create([DataSourceRequest] DataSourceRequest request, TweetInputModel tweetModel) { if (tweetModel != null && this.ModelState.IsValid) { var tweet = Mapper.Map <Tweet>(tweetModel); this.Data.Tweets.Add(tweet); this.Data.SaveChanges(); } return(this.Json(new[] { tweetModel }.ToDataSourceResult(request, this.ModelState))); }
public ActionResult EditingInline_Destroy([DataSourceRequest] DataSourceRequest request, TweetInputModel tweetModel) { if (tweetModel != null && this.ModelState.IsValid) { var tweet = this.Data .Tweets .All() .FirstOrDefault(t => t.Id == tweetModel.Id); this.Data.Tweets.Remove(tweet); this.Data.SaveChanges(); } return this.Json(new[] { tweetModel }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult Add(TweetInputModel model) { if (model == null || !this.ModelState.IsValid) { return(this.View(model)); } var tweet = new Tweet { Text = model.Text, UserId = this.UserProfille.Id }; this.Data.Tweets.Add(tweet); this.Data.SaveChanges(); return(this.RedirectToAction("View", new { id = tweet.Id })); }
public ActionResult EditingInline_Destroy([DataSourceRequest] DataSourceRequest request, TweetInputModel tweetModel) { if (tweetModel != null && this.ModelState.IsValid) { var tweet = this.Data .Tweets .All() .FirstOrDefault(t => t.Id == tweetModel.Id); this.Data.Tweets.Remove(tweet); this.Data.SaveChanges(); } return(this.Json(new[] { tweetModel }.ToDataSourceResult(request, this.ModelState))); }
public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, TweetInputModel tweetModel) { if (tweetModel != null && this.ModelState.IsValid) { var tweet = this.Data .Tweets .All() .FirstOrDefault(t => t.Id == tweetModel.Id); tweet.Text = tweetModel.Text; tweet.AuthorId = tweetModel.AuthorId; tweet.CreatedOn = tweetModel.CreatedOn; this.Data.SaveChanges(); } return this.Json(new[] { tweetModel }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, TweetInputModel tweetModel) { if (tweetModel != null && this.ModelState.IsValid) { var tweet = this.Data .Tweets .All() .FirstOrDefault(t => t.Id == tweetModel.Id); tweet.Text = tweetModel.Text; tweet.AuthorId = tweetModel.AuthorId; tweet.CreatedOn = tweetModel.CreatedOn; this.Data.SaveChanges(); } return(this.Json(new[] { tweetModel }.ToDataSourceResult(request, this.ModelState))); }
public ActionResult Create(TweetInputModel model) { var context = new ApplicationContext(); var user = new IdentityUser { Id = User.Identity.GetUserId() }; context.Users.Attach(user); var tweet = new Tweet { Text = model.Text, Author = user, PublishDateTime = DateTime.Now }; context.Tweets.Add(tweet); context.SaveChanges(); context.Dispose(); return(View()); }
public ActionResult Create(TweetInputModel model) { if (!this.ModelState.IsValid) { return(View(model)); } var text = model.Content; var tweet = new Tweet() { AuthorId = this.User.Identity.GetUserId(), Content = text, }; string hashRegex = @"(?<=\s|^)#(\w*[A-Za-z_]+\w*)"; MatchCollection hashes = Regex.Matches(text, hashRegex); foreach (Match item in hashes) { var hashTagValue = item.Value; var hashTag = data.HashTags.All().FirstOrDefault(x => x.Name == hashTagValue); if (hashTag == null) { hashTag = new HashTag() { Name = hashTagValue }; } tweet.HashTags.Add(hashTag); } data.Tweets.Add(tweet); data.SaveChanges(); return(RedirectToAction(nameof(MyTweets))); }