Exemplo n.º 1
0
        public void addhash(List <string> hashes, int cid)
        {
            for (int i = 0; i < hashes.Count; i++)
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    String str = hashes[i];

                    var hsh   = dbContext.Hashes.Where(s => s.Content == str).FirstOrDefault();
                    var maxid = 0;
                    if (hsh == null)
                    {
                        Hash hash = new Hash()
                        {
                            Content = hashes[i],
                            //PostDate = DateTime.Now,
                            HashCount   = 1,                          //Alert
                            SearchCount = 0
                        };
                        dbContext.Hashes.Add(hash);
                        dbContext.SaveChanges();
                        //var maxid=dbContext.Hashes.SqlQuery<Int32>("Select Max(HashId) From Hash");
                        maxid = dbContext.Hashes.Max(s => s.HashId);
                        var             x  = dbContext.Hashes.Where(s => s.Content == hashes[i]);
                        TweetHashMapper mp = new TweetHashMapper()
                        {
                            TweetId = cid,
                            HashId  = (int)maxid
                        };
                        dbContext.TweetHashMappers.Add(mp);
                    }
                    else
                    {
                        String st   = hashes[i];
                        Hash   hash = dbContext.Hashes.Where(s => s.Content == st).FirstOrDefault();
                        hash.HashCount += 1;
                        TweetHashMapper mp = new TweetHashMapper()
                        {
                            TweetId = cid,
                            HashId  = hash.HashId
                        };
                        dbContext.TweetHashMappers.Add(mp);
                        //dbContext.Database.SqlQuery<Hash>("Update hash set hashcount=hashcount+1 where Content=" + hashes[i]);
                    }
                    //dbContext.Tweets.Add(tweet);
                    dbContext.SaveChanges();
                }
            }
            return;
        }
Exemplo n.º 2
0
        public void AddNewTweetHash(List <string> hashes, int tweetId)
        {
            for (int i = 0; i < hashes.Count; i++)
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    String str = hashes[i];

                    var hsh   = dbContext.Hashes.Where(s => s.Content == str).FirstOrDefault();
                    var maxid = 0;
                    if (hsh == null)
                    {
                        Hash hash = new Hash()
                        {
                            Content     = hashes[i],
                            HashCount   = 1,//Alert
                            SearchCount = 0
                        };
                        dbContext.Hashes.Add(hash);
                        dbContext.SaveChanges();//
                        maxid = dbContext.Hashes.Max(s => s.HashId);
                        var             x       = dbContext.Hashes.Where(s => s.Content == hashes[i]);
                        TweetHashMapper mpEntry = new TweetHashMapper()
                        {
                            TweetId = tweetId,
                            HashId  = (int)maxid
                        };
                        dbContext.TweetHashMappers.Add(mpEntry);
                        dbContext.SaveChanges();//
                    }
                    else
                    {
                        String st   = hashes[i];
                        Hash   hash = dbContext.Hashes.Where(s => s.Content == st).FirstOrDefault();
                        hash.HashCount += 1;
                        TweetHashMapper mp = new TweetHashMapper()
                        {
                            TweetId = tweetId,
                            HashId  = hash.HashId
                        };
                        dbContext.TweetHashMappers.Add(mp);
                    }
                    dbContext.SaveChanges();//
                }
            }
            return;
        }