private bool CheckUserRights(Tweet tweet) { if (User.IsInRole("admin")) { return true; } else if (User.Identity.GetUserId() == tweet.UserId) { return true; } else { return false; } }
public void TweetsListView_InsertItem() { using (var context = new TwitterEntities()) { var control = TweetsListView.InsertItem; try { Tweet newTweet = new Tweet() { DatePosted = DateTime.Now, UserId = Context.User.Identity.GetUserId(), TweetText = (control.FindControl("TweetTextTb") as TextBox).Text, TweetTitle = (control.FindControl("TweetTitleTb") as TextBox).Text, }; context.Tweets.Add(newTweet); context.SaveChanges(); ErrorSuccessNotifier.AddSuccessMessage("Tweet created."); } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage(ex); } } }