Esempio n. 1
0
        public ActionResult ManageTweets(TweetsModel model)
        {
            MarketingService _attSvc = new MarketingService();

            TweetsBE tweet = new TweetsBE();

            tweet.UserId   = model.UserId;
            tweet.UserName = model.UserName;
            tweet.Tweet    = model.Tweet;
            tweet.Date     = model.Date;
            tweet.Location = "Riyadh, KSA";

            if (_attSvc.AddTweet(tweet))
            {
                ModelState.AddModelError("", "Tweet Saved Successfully");
            }
            else
            {
                ModelState.AddModelError("", "Unable to Save Tweet");
            }

            model.TweetsList = _attSvc.GetAllTweets();

            return(View(model));
        }
Esempio n. 2
0
        public bool AddTweet(TweetsBE tweet)
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = @"Data Source=localhost\sqlexpress; Initial Catalog=ERP; Integrated Security=true;";
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;

                cmd.CommandText = "Insert into tTweets (UserId, UserName, Date, Tweet, Location) values(@UserId, @UserName, @Date, @Tweet, @Location)";
                cmd.Parameters.AddWithValue("@UserId", tweet.UserId);
                cmd.Parameters.AddWithValue("@UserName", tweet.UserName);
                cmd.Parameters.AddWithValue("@Date", tweet.Date);
                cmd.Parameters.AddWithValue("@Tweet", tweet.Tweet);
                cmd.Parameters.AddWithValue("@Location", tweet.Location);

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }
            return(true);
        }
Esempio n. 3
0
        public List <TweetsBE> GetAllTweets()
        {
            List <TweetsBE> tweetsList = new List <TweetsBE>();

            SqlConnection con = new SqlConnection();

            con.ConnectionString = @"Data Source=localhost\sqlexpress; Initial Catalog=ERP; Integrated Security=true;";
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = con;
                cmd.CommandText = "select * from tTweets";

                SqlDataReader rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        TweetsBE twt = new TweetsBE();
                        twt.KeyId    = (int)rdr["KeyId"];
                        twt.UserId   = (string)rdr["UserId"];
                        twt.Date     = (DateTime)rdr["Date"];
                        twt.Tweet    = (string)rdr["Tweet"];
                        twt.UserName = (string)rdr["UserName"];
                        twt.Location = (string)rdr["Location"];

                        tweetsList.Add(twt);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }

            return(tweetsList);
        }
Esempio n. 4
0
 public bool ModifyTweet(TweetsBE tweet)
 {
     //Not yet Defined
     throw new NotImplementedException();
 }