public ActionResult TweetAdminViewModels_Destroy([DataSourceRequest]DataSourceRequest request, TweetAdminViewModel tweet) { if (ModelState.IsValid) { var entity = new Tweet() { Id = tweet.Id, Title = tweet.Title, Content = tweet.Content }; tweets.Delete(entity); tweets.SaveChanges(); } return Json(new[] { tweet }.ToDataSourceResult(request, ModelState)); }
public ActionResult Create(TweetViewModel tweet) { if (ModelState.IsValid) { var newTweet = new Tweet() { Content = tweet.Content, CreatedDate = DateTime.UtcNow, Title = tweet.Title, UserId = this.UserProfile.Id }; tweets.Add(newTweet); tweets.SaveChanges(); var givenTags = tweet.Tags.Split(';'); foreach (var tag in givenTags) { var tagDb = this.tags.All().FirstOrDefault(t => t.Title == tag); if (tagDb != null) { tagDb.Tweets.Add(newTweet); this.tags.Update(tagDb); } else { var newTag = new Tag() {Title = tag}; newTag.Tweets.Add(newTweet); this.tags.Add(newTag); } } this.tags.SaveChanges(); return RedirectToAction("Mine"); } return View(tweet); }