Пример #1
0
 private bool CheckUserRights(Tweet tweet)
 {
     if (User.IsInRole("admin"))
     {
         return true;
     }
     else if (User.Identity.GetUserId() == tweet.UserId)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #2
0
        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);
                }
            }
        }