Пример #1
0
 public static void InsertMovieUser(this DbTorronto db, int movieId, int?userId)
 {
     db.Insert(new MovieUser
     {
         Created = DateTime.UtcNow,
         MovieID = movieId,
         UserID  = userId.GetValueOrDefault()
     });
 }
Пример #2
0
        public void AddTorrentUserLink(int torrentID, int?userId, bool subscribe, bool rss)
        {
            if (userId == null)
            {
                return;
            }

            using (var db = new DbTorronto())
            {
                var update = db.TorrentUser
                             .Where(tu => tu.UserID == userId && tu.TorrentID == torrentID)
                             .AsUpdatable();

                if (subscribe)
                {
                    update = update.Set(f => f.IsSubscribed, true);
                }

                if (rss)
                {
                    update = update.Set(f => f.AddedRss, DateTime.UtcNow);
                }

                var affected = update.Update();

                if (affected == 0)
                {
                    var newTu = new TorrentUser
                    {
                        EmailSent = null,
                        UserID    = userId.GetValueOrDefault(),
                        TorrentID = torrentID
                    };

                    if (subscribe)
                    {
                        newTu.IsSubscribed = true;
                    }
                    if (rss)
                    {
                        newTu.AddedRss = DateTime.UtcNow;
                    }

                    db.Insert(newTu);
                }
            }
        }
Пример #3
0
        public void SaveToDb(List <Torrent> torrents)
        {
            using (var db = new DbTorronto())
            {
                foreach (var torrent in torrents)
                {
                    var existing = db.Torrent
                                   .FirstOrDefault(x => x.SiteID == torrent.SiteID);

                    if (existing == null)
                    {
                        torrent.Updated = DateTime.UtcNow;
                        db.Insert(torrent);
                    }
                    else
                    {
                        db.Torrent
                        .Where(x => x.ID == existing.ID)
                        .Set(f => f.Title, torrent.Title)
                        .Set(f => f.InfoHash, torrent.InfoHash)
                        .Set(f => f.Size, torrent.Size)
                        .Set(f => f.Updated, DateTime.UtcNow)
                        .Update();

                        if (existing.Size != torrent.Size)
                        {
                            var subscribers = from tu in db.TorrentUser
                                              join u in db.User on tu.UserID equals u.ID
                                              where tu.IsSubscribed && tu.TorrentID == existing.ID
                                              select u;

                            existing.Title = torrent.Title;

                            foreach (var subscriber in subscribers)
                            {
                                _emailService.NotifyUserAboutTorrent(subscriber, existing);
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public User AttachIdentity(int?userID, string name, string email, string providerName, string providerId)
        {
            using (var db = new DbTorronto())
            {
                var user = db.User
                           .FirstOrDefault(u => u.ID == userID);

                var identity = new UserIdentity
                {
                    UserID           = user.ID.GetValueOrDefault(),
                    Email            = email,
                    AuthProviderID   = providerId,
                    AuthProviderName = providerName,
                    DisplayName      = name,
                    Created          = DateTime.UtcNow,
                };

                db.Insert(identity);

                return(user);
            }
        }
Пример #5
0
        public User AddUser(string name, string email, string providerName, string providerId)
        {
            using (var db = new DbTorronto())
                using (db.BeginTransaction())
                {
                    var user = new User
                    {
                        Identifier       = Guid.NewGuid(),
                        DisplayName      = name,
                        AuthProviderID   = string.Empty,
                        AuthProviderName = string.Empty,
                        Password         = "******",
                        Email            = email,
                        Created          = DateTime.UtcNow,
                        Updated          = DateTime.UtcNow,
                        FilterSizes      = string.Empty
                    };

                    user.ID = Convert.ToInt32(
                        db.InsertWithIdentity(user)
                        );

                    var identity = new UserIdentity
                    {
                        UserID           = user.ID.GetValueOrDefault(),
                        Email            = email,
                        AuthProviderID   = providerId,
                        AuthProviderName = providerName,
                        DisplayName      = name,
                        Created          = DateTime.UtcNow,
                    };

                    db.Insert(identity);
                    db.CommitTransaction();

                    return(user);
                }
        }
Пример #6
0
        private static void SplitIdentities()
        {
            using (var db = new DbTorronto())
            {
                var users = db.User
                            .Where(u => u.AuthProviderID.Length > 0)
                            .ToList();

                foreach (var user in users)
                {
                    var identity = new UserIdentity
                    {
                        Created          = DateTime.UtcNow,
                        AuthProviderID   = user.AuthProviderID,
                        AuthProviderName = user.AuthProviderName,
                        DisplayName      = user.DisplayName,
                        Email            = user.Email,
                        UserID           = user.ID.GetValueOrDefault()
                    };

                    db.Insert(identity);
                }
            }
        }
Пример #7
0
        public void AddMovieUserLink(int movieId, int?userId, bool?waitlist, bool?watched, int?mark, bool?dontwant)
        {
            if (userId == null)
            {
                return;
            }

            using (var db = new DbTorronto())
            {
                var newMark = _marks
                              .TakeWhile(x => x <= mark)
                              .LastOrDefault();

                var update = db.MovieUser
                             .Where(mu => mu.UserID == userId && mu.MovieID == movieId)
                             .AsUpdatable();

                if (waitlist == true)
                {
                    update = update.Set(f => f.IsWaitlist, true);
                }

                if (watched == true)
                {
                    update = update
                             .Set(f => f.IsWatched, true)
                             .Set(f => f.IsWaitlist, false)
                             .Set(f => f.IsDontWant, false);
                }

                if (dontwant == true)
                {
                    update = update
                             .Set(f => f.IsDontWant, true)
                             .Set(f => f.IsWatched, false)
                             .Set(f => f.IsWaitlist, false)
                             .Set(f => f.Mark, (int?)null);
                }

                if (newMark > 0)
                {
                    update = update
                             .Set(f => f.Mark, newMark)
                             .Set(f => f.IsWatched, true)
                             .Set(f => f.IsWaitlist, false)
                             .Set(f => f.IsDontWant, false);
                }

                var affected = update.Update();

                if (affected == 0)
                {
                    var newMu = new MovieUser
                    {
                        Created = DateTime.UtcNow,
                        UserID  = userId.GetValueOrDefault(),
                        MovieID = movieId
                    };

                    if (waitlist == true)
                    {
                        newMu.IsWaitlist = true;
                    }
                    if (watched == true)
                    {
                        newMu.IsWatched = true;
                    }
                    if (dontwant == true)
                    {
                        newMu.IsDontWant = true;
                    }
                    if (newMark > 0)
                    {
                        newMu.Mark      = newMark;
                        newMu.IsWatched = true;
                    }

                    db.Insert(newMu);
                }
            }
        }