예제 #1
0
        public static void LoadNews(string filename)
        {

            using (TwitterDbContext db = new TwitterDbContext())
            {
                long? minId = (from t in db.Tweets where t.ProfileId == -1 select (long?)t.Id).Min();

                if (!minId.HasValue)
                    minId = 0;

                using (StreamReader sr = new StreamReader(filename))
                {
                    while (!sr.EndOfStream)
                    {
                        string title = sr.ReadLine();
                        string[] tokens = title.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                        if (tokens.Length != 3)
                            continue;

                        TwitterTweet tweet = new TwitterTweet { Id = (--minId).Value, ProfileId = -2, CreatedBy = tokens[0], CreatedAt = DateTime.Parse(tokens[1]), Text = tokens[2] };
                        db.Entry<TwitterTweet>(tweet).State = System.Data.Entity.EntityState.Added;
                    }


                }

                db.SaveChanges();
            }


        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Tag tag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tag));
 }
예제 #3
0
 public ActionResult Edit([Bind(Include = "Id,Message,UserId,CreatedOn")] Tweet tweet)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tweet).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.Users, "Id", "Email", tweet.UserId);
     return(View(tweet));
 }
예제 #4
0
 public void UpdateModel(T model)
 {
     _db.Entry(model).State = EntityState.Modified;
     _db.SaveChanges();
 }