Ejemplo n.º 1
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);
                }
        }
Ejemplo n.º 2
0
        public void MergeAccounts(int sourceId, int destinationId)
        {
            using (var db = new DbTorronto())
                using (var trans = db.BeginTransaction())
                {
                    db.UserIdentity
                    .Where(x => x.UserID == sourceId)
                    .Set(f => f.UserID, destinationId)
                    .Update();

                    // transfer torrents

                    var sourceTorrents = db.TorrentUser
                                         .Where(x => x.UserID == sourceId)
                                         .Select(x => x.TorrentID)
                                         .ToList();

                    var destTorrents = db.TorrentUser
                                       .Where(x => x.UserID == destinationId)
                                       .Select(x => x.TorrentID)
                                       .ToList();

                    var updateTorrents = sourceTorrents
                                         .Except(destTorrents);

                    db.TorrentUser
                    .Where(x => updateTorrents.Contains(x.TorrentID) && x.UserID == sourceId)
                    .Set(f => f.UserID, destinationId)
                    .Update();

                    // transfer movies

                    var sourceMovies = db.MovieUser
                                       .Where(x => x.UserID == sourceId)
                                       .Select(x => x.MovieID)
                                       .ToList();

                    var destMovies = db.MovieUser
                                     .Where(x => x.UserID == destinationId)
                                     .Select(x => x.MovieID)
                                     .ToList();

                    var updateMovies = sourceMovies
                                       .Except(destMovies);

                    db.MovieUser
                    .Where(x => updateMovies.Contains(x.MovieID) && x.UserID == sourceId)
                    .Set(f => f.UserID, destinationId)
                    .Update();

                    //remove all source items

                    db.TorrentUser
                    .Where(x => x.UserID == sourceId)
                    .Delete();

                    db.MovieUser
                    .Where(x => x.UserID == sourceId)
                    .Delete();

                    db.User
                    .Where(x => x.ID == sourceId)
                    .Delete();

                    trans.Commit();
                }
        }