Example #1
0
        public HttpResponseMessage GetArtistByID(HttpRequestMessage request, int ID)
        {
            ArtistManager ArtistMgr = new ArtistManager();
            Artist        result    = ArtistMgr.getArtistByID(ID);

            return(request.CreateResponse <Artist>(HttpStatusCode.OK, result));
        }
Example #2
0
        public HttpResponseMessage UpsertArtist(HttpRequestMessage request, Artist Artist)
        {
            ArtistManager ArtistMgr = new ArtistManager();
            Artist        result    = ArtistMgr.UpsertArtist(Artist);

            return(request.CreateResponse <Artist>(HttpStatusCode.OK, result));
        }
Example #3
0
        protected override void Dispose(bool disposing)
        {
            // Dispose managed
            if (disposing)
            {
            }

            // Dispose unmanaged
            if (!IsInvalid)
            {
                try
                {
                    lock (Spotify.Mutex)
                    {
                        Spotify.sp_artist_release(Handle);
                    }
                }
                catch
                {
                }
                finally
                {
                    ArtistManager.Remove(Handle);
                    Handle = IntPtr.Zero;
                }
            }

            Debug.WriteLine("Artist disposed");
            base.Dispose(disposing);
        }
Example #4
0
        public HttpResponseMessage GetArtist(HttpRequestMessage request)
        {
            ArtistManager        ArtistMgr = new ArtistManager();
            IEnumerable <Artist> result    = ArtistMgr.getArtist();

            return(request.CreateResponse <IEnumerable <Artist> >(HttpStatusCode.OK, result));
        }
Example #5
0
        private IArtist GetArtistAtIndex(int index)
        {
            AssertHandle();

            lock (Spotify.Mutex)
            {
                return(ArtistManager.Get(Session, Spotify.sp_toplistbrowse_artist(Handle, index)));
            }
        }
Example #6
0
        protected IArtist GetArtistIndex(int index)
        {
            AssertHandle();

            lock (Spotify.Mutex)
            {
                return(ArtistManager.Get(Session, Spotify.sp_search_artist(Handle, index)));
            }
        }
        public IActionResult UpdateArtistManager(int artistId, int artistManagerId, ArtistManager artistManager)
        {
            try
            {
                if (!ClientKeyIsValid())
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthenticatedAndAuthorized(MethodBase.GetCurrentMethod()))
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthorizedForArtist(artistId))
                {
                    return(Unauthorized());
                }

                var invalidArtistPathResult = InvalidArtistPathResult(artistId);
                if (invalidArtistPathResult != null)
                {
                    return(invalidArtistPathResult);
                }

                var getArtistManagerResult = _getArtistManagerTask.DoTask(artistManagerId);

                if (getArtistManagerResult.HasException)
                {
                    return(Error(getArtistManagerResult.Exception));
                }

                if (getArtistManagerResult.HasNoData)
                {
                    return(NotFound());
                }

                if (getArtistManagerResult.Data.ArtistId != artistId)
                {
                    return(BadRequest());
                }

                artistManager.ArtistId = artistId;
                artistManager.Id       = artistManagerId;
                var taskResults = _updateArtistManagerTask.DoTask(artistManager);

                return(taskResults.Success ?
                       Ok() :
                       Error(taskResults.Exception));
            }
            catch (Exception e)
            {
                return(Error(e));
            }
        }
Example #8
0
        private async Task <ArtistManager> CreateArtistService(IEnumerable <Artist> testData)
        {
            await context.Artists.AddRangeAsync(testData);

            await context.SaveChangesAsync();

            var artistRepository = new ArtistRepository(context);
            var service          = new ArtistManager(artistRepository);

            return(service);
        }
Example #9
0
        public async Task <ArtistController> CreateControllerAsync(IEnumerable <Artist> testData)
        {
            await context.Artists.AddRangeAsync(testData);

            await context.SaveChangesAsync();

            var artistRepository = new ArtistRepository(context);
            var service          = new ArtistManager(artistRepository);

            return(new ArtistController(service));
        }
Example #10
0
        public void CreateNullTest()
        {
            ArtistManager artistMng = new ArtistManager();
            Artist        artist    = null;

            Response actual   = artistMng.Create(artist);
            bool     expected = false;

            Console.WriteLine(actual.Message);
            Assert.AreEqual(expected, actual.Status);
        }
 public DatabaseConnection(ConnectionType type, string connection = null)
 {
     database           = DatabaseFactory.GetDatabase(type, connection);
     ArtistManager      = new ArtistManager(DatabaseFactory.GetDatabase(type, connection));
     ProductManager     = new ProductManager(DatabaseFactory.GetDatabase(type, connection));
     UserManager        = new UserManager(DatabaseFactory.GetDatabase(type, connection));
     OrderManager       = new OrderManager(DatabaseFactory.GetDatabase(type, connection));
     CartManager        = new CartManager(DatabaseFactory.GetDatabase(type, connection));
     CartItemManager    = new CartItemManager(DatabaseFactory.GetDatabase(type, connection));
     OrderNumberManager = new OrderNumberManager(DatabaseFactory.GetDatabase(type, connection));
 }
Example #12
0
        public override void Initialize()
        {
            _artist = new Lazy <IArtist>(
                () =>
            {
                AssertHandle();

                lock (Spotify.Mutex)
                {
                    return(ArtistManager.Get(Session, Spotify.sp_link_as_artist(Handle)));
                }
            });
        }
Example #13
0
        public void CreateTest()
        {
            ArtistManager artistMng = new ArtistManager();
            Artist        artist    = new Artist()
            {
                name = "Artista de prueba"
            };

            Response actual   = artistMng.Create(artist);
            bool     expected = true;

            Console.WriteLine(actual.Message);

            Assert.AreEqual(expected, actual.Status);
        }
Example #14
0
        public async Task GetAll_WorksProperly()
        {
            var artist1 = new Artist()
            {
                FirstName = "TestFirst",
                LastName  = "TestLast",
                Nickname  = "Test",
                Genre     = Genre.Pop
            };
            var artist2 = new Artist()
            {
                FirstName = "TestFirst2",
                LastName  = "TestLast2",
                Nickname  = "Test2",
                Genre     = Genre.Pop
            };

            var list = new List <Artist>();

            list.Add(artist1);
            list.Add(artist2);


            var repoMock = new Mock <ArtistRepository>(context);

            repoMock.Setup(r => r.All()).Returns(list.AsQueryable());

            var service = new ArtistManager(repoMock.Object);

            var all = service.GetAll().ToList();

            Assert.AreEqual(list, all);

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(list[i].FirstName, all[i].FirstName);
            }
        }
Example #15
0
        public TaskResult <Nothing> DoTask(ArtistManager update)
        {
            try
            {
                var artistManager = _dbContext.ArtistManagers.SingleOrDefault(am => am.Id == update.Id);
                if (artistManager == null)
                {
                    throw new TaskException(SystemMessage("ARTIST_MANAGER_NOT_FOUND"));
                }

                var hasEnded = update.EndedOn.HasValue && update.EndedOn.Value <= DateTime.Today;
                artistManager.StartedOn = update.StartedOn;
                artistManager.EndedOn   = update.EndedOn;
                artistManager.IsActive  = !hasEnded;
                _dbContext.SaveChanges();

                return(new TaskResult <Nothing>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <Nothing>(new TaskException(e)));
            }
        }
        public IActionResult AddArtistManager(int artistId, ArtistManager artistManager)
        {
            try
            {
                if (!ClientKeyIsValid())
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthenticatedAndAuthorized(MethodBase.GetCurrentMethod()))
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthorizedForArtist(artistId))
                {
                    return(Unauthorized());
                }

                var invalidArtistPathResult = InvalidArtistPathResult(artistId);
                if (invalidArtistPathResult != null)
                {
                    return(invalidArtistPathResult);
                }

                artistManager.ArtistId = artistId;
                var taskResults = _addArtistManagerTask.DoTask(artistManager);

                return(taskResults.Success ?
                       Json(taskResults) :
                       Error(taskResults.Exception));
            }
            catch (Exception e)
            {
                return(Error(e));
            }
        }
        public TaskResult <int?> DoTask(ArtistManager artistManager)
        {
            try
            {
                var artistId = artistManager.Artist?.Id ?? artistManager.ArtistId;
                var personId = artistManager.Manager?.Id ?? artistManager.PersonId;
                var hasEnded = artistManager.EndedOn.HasValue && artistManager.EndedOn.Value <= DateTime.Today;

                artistManager.Artist   = null;
                artistManager.ArtistId = artistId;
                artistManager.Manager  = null;
                artistManager.PersonId = personId;
                artistManager.IsActive = !hasEnded;

                _dbContext.ArtistManagers.Add(artistManager);
                _dbContext.SaveChanges();

                return(new TaskResult <int?>(artistManager.Id));
            }
            catch (Exception e)
            {
                return(new TaskResult <int?>(new TaskException(e)));
            }
        }
 public ArtistsController(ArtistManager artistManager)
 {
     this.artistManager = artistManager;
 }
Example #19
0
        public void TaskSuccessTest()
        {
            var testArtist      = TestsModel.Artist;
            var addArtistTask   = new AddArtist(DbContext, new FormattingService());
            var addArtistResult = addArtistTask.DoTask(testArtist);

            Assert.IsTrue(addArtistResult.Success);
            Assert.IsNull(addArtistResult.Exception);

            var artistId = addArtistResult.Data;

            Assert.IsNotNull(artistId);
            Assert.IsTrue(artistId > 0);

            var addPersonTask   = new AddPerson(DbContext, new FormattingService());
            var testPerson      = TestsModel.Person;
            var addPersonResult = addPersonTask.DoTask(testPerson);

            Assert.IsTrue(addPersonResult.Success);
            Assert.IsNull(addPersonResult.Exception);
            Assert.IsNotNull(addPersonResult.Data);

            var managerPerson = testPerson;
            var artistManager = new ArtistManager
            {
                Artist    = testArtist,
                Manager   = managerPerson,
                StartedOn = DateTime.Now.AddMonths(-8)
            };

            var addArtistManagerTask   = new AddArtistManager(DbContext);
            var addArtistManagerResult = addArtistManagerTask.DoTask(artistManager);

            Assert.IsTrue(addArtistManagerResult.Success);
            Assert.IsNull(addArtistManagerResult.Exception);
            Assert.IsNotNull(addArtistManagerResult.Data);

            var getArtistManagerTask   = new GetArtistManager(DbContext);
            var getArtistManagerResult = getArtistManagerTask.DoTask(artistManager.Id);

            Assert.IsTrue(getArtistManagerResult.Success);
            Assert.IsNull(getArtistManagerResult.Exception);
            Assert.IsNotNull(getArtistManagerResult.Data);

            var manager = getArtistManagerResult.Data;

            Assert.IsNotNull(manager);
            Assert.AreEqual(artistManager.StartedOn, manager.StartedOn);
            Assert.AreEqual(artistManager.EndedOn, manager.EndedOn);
            Assert.AreEqual(artistManager.IsActive, manager.IsActive);

            manager.EndedOn = DateTime.Now.AddDays(-1);

            var task   = new UpdateArtistManager(DbContext);
            var result = task.DoTask(manager);

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Exception);

            getArtistManagerTask   = new GetArtistManager(DbContext);
            getArtistManagerResult = getArtistManagerTask.DoTask(artistManager.Id);

            Assert.IsTrue(getArtistManagerResult.Success);
            Assert.IsNull(getArtistManagerResult.Exception);
            Assert.IsNotNull(getArtistManagerResult.Data);

            var updatedManager = getArtistManagerResult.Data;

            Assert.IsNotNull(updatedManager);
            Assert.AreEqual(manager.StartedOn, updatedManager.StartedOn);
            Assert.AreEqual(manager.EndedOn, updatedManager.EndedOn);
            Assert.AreEqual(false, updatedManager.IsActive);

            var removeArtistTask   = new RemoveArtist(DbContext);
            var removeArtistResult = removeArtistTask.DoTask(testArtist);

            Assert.IsTrue(removeArtistResult.Success);
            Assert.IsNull(removeArtistResult.Exception);

            var removePersonTask   = new RemovePerson(DbContext);
            var removePersonResult = removePersonTask.DoTask(managerPerson);

            Assert.IsTrue(removePersonResult.Success);
            Assert.IsNull(removePersonResult.Exception);
        }
Example #20
0
        public void TaskSuccessTest()
        {
            var addArtistTask   = new AddArtist(DbContext, new FormattingService());
            var testArtist      = TestsModel.Artist;
            var addArtistResult = addArtistTask.DoTask(testArtist);

            Assert.IsTrue(addArtistResult.Success);
            Assert.IsNull(addArtistResult.Exception);
            Assert.IsNotNull(addArtistResult.Data);

            var artistId = addArtistResult.Data;

            Assert.IsNotNull(artistId);
            Assert.IsTrue(artistId > 0);

            var addPersonTask   = new AddPerson(DbContext, new FormattingService());
            var testPerson      = TestsModel.Person;
            var addPersonResult = addPersonTask.DoTask(testPerson);

            Assert.IsTrue(addPersonResult.Success);
            Assert.IsNull(addPersonResult.Exception);
            Assert.IsNotNull(addPersonResult.Data);

            var managerPerson = testPerson;
            var artistManager = new ArtistManager
            {
                Artist    = testArtist,
                Manager   = managerPerson,
                StartedOn = DateTime.Now.AddMonths(-14)
            };

            var task   = new AddArtistManager(DbContext);
            var result = task.DoTask(artistManager);

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Exception);
            Assert.IsNotNull(result.Data);

            var listArtistManagersTask   = new ListArtistManagers(DbContext);
            var listArtistManagersResult = listArtistManagersTask.DoTask(testArtist);

            Assert.IsTrue(listArtistManagersResult.Success);
            Assert.IsNull(listArtistManagersResult.Exception);
            Assert.IsNotNull(listArtistManagersResult.Data);

            var manager = listArtistManagersResult.Data.SingleOrDefault(m => m.Id == artistManager.Id);

            Assert.IsNotNull(manager);
            Assert.AreEqual(artistManager.StartedOn, manager.StartedOn);
            Assert.AreEqual(artistManager.EndedOn, manager.EndedOn);
            Assert.AreEqual(artistManager.IsActive, manager.IsActive);

            var removeArtistTask   = new RemoveArtist(DbContext);
            var removeArtistResult = removeArtistTask.DoTask(testArtist);

            Assert.IsTrue(removeArtistResult.Success);
            Assert.IsNull(removeArtistResult.Exception);

            var removePersonTask   = new RemovePerson(DbContext);
            var removePersonResult = removePersonTask.DoTask(managerPerson);

            Assert.IsTrue(removePersonResult.Success);
            Assert.IsNull(removePersonResult.Exception);
        }
Example #21
0
 public ArtistController(ArtistManager manager)
 {
     this.manager = manager;
 }
Example #22
0
        public TaskResult <User> DoTask(UserInvitation userInvitation)
        {
            try
            {
                var invitation = _dbContext.UserInvitations.Where(ui => ui.Uuid == userInvitation.Uuid)
                                 .Include(ui => ui.InvitedByUser)
                                 .Single();

                if (invitation.Type == UserType.Unassigned)
                {
                    throw new TaskException(SystemMessage("USER_INVITATION_UNASSIGNED"));
                }

                var newUser = userInvitation.CreatedUser;
                newUser.AuthenticationId = invitation.Email;
                newUser.Type             = invitation.Type;
                newUser.Roles            = invitation.Roles;

                var newPerson = newUser.Person;
                newPerson.Email = invitation.Email;
                var addPersonResult = _addPersonTask.DoTask(newPerson);
                if (!addPersonResult.Success)
                {
                    throw addPersonResult.Exception;
                }

                var personId      = addPersonResult.Data;
                var proId         = newUser.PerformingRightsOrganization?.Id ?? newUser.PerformingRightsOrganizationId;
                var publisherId   = invitation.Publisher?.Id ?? invitation.PublisherId;
                var recordLabelId = invitation.RecordLabel?.Id ?? invitation.RecordLabelId;
                var artistId      = invitation.Artist?.Id ?? invitation.ArtistId;

                newUser.Person   = null;
                newUser.PersonId = personId;
                newUser.PerformingRightsOrganization   = null;
                newUser.PerformingRightsOrganizationId = proId;
                newUser.Publisher     = null;
                newUser.PublisherId   = publisherId;
                newUser.RecordLabel   = null;
                newUser.RecordLabelId = recordLabelId;

                _dbContext.Users.Add(newUser);
                _dbContext.SaveChanges();

                invitation.CreatedUser   = null;
                invitation.CreatedUserId = newUser.Id;
                invitation.AcceptedOn    = DateTime.UtcNow;
                _dbContext.SaveChanges();

                invitation.CreatedUser = newUser;

                if (artistId.HasValue)
                {
                    var artist = _dbContext.Artists.Single(a => a.Id == artistId.Value);
                    if (invitation.Roles.HasFlag(SystemUserRoles.ArtistMember))
                    {
                        var artistMember = new ArtistMember
                        {
                            Artist    = artist,
                            Member    = newPerson,
                            StartedOn = DateTime.Today
                        };
                        var addArtistMemberResult = _addArtistMember.DoTask(artistMember);
                        if (!addArtistMemberResult.Success)
                        {
                            throw addArtistMemberResult.Exception;
                        }
                    }
                    else if (invitation.Roles.HasFlag(SystemUserRoles.ArtistManager))
                    {
                        var artistManager = new ArtistManager
                        {
                            Artist    = artist,
                            Manager   = newPerson,
                            StartedOn = DateTime.Today
                        };
                        var addArtistManagerResult = _addArtistManager.DoTask(artistManager);
                        if (!addArtistManagerResult.Success)
                        {
                            throw addArtistManagerResult.Exception;
                        }
                    }
                }

                newUser.Person = newPerson;
                newUser.PerformingRightsOrganization = proId > 0 ?
                                                       _dbContext.PerformingRightsOrganizations.Where(p => p.Id == proId)
                                                       .Include(p => p.Country)
                                                       .SingleOrDefault() : null;
                newUser.Publisher = publisherId > 0 ?
                                    _dbContext.Publishers.Where(p => p.Id == publisherId)
                                    .Include(p => p.Address).ThenInclude(a => a.Country)
                                    .SingleOrDefault() : null;
                newUser.RecordLabel = recordLabelId > 0 ?
                                      _dbContext.RecordLabels.Where(l => l.Id == recordLabelId)
                                      .Include(p => p.Address).ThenInclude(a => a.Country)
                                      .SingleOrDefault() : null;

                userInvitation.LoginLink = ApplicationSettings.Web.Domain + WebRoutes.Login;
                var installation  = _getInstallationTask.DoTask(null).Data;
                var emailTemplate = EmailTemplate($"{invitation.Type}Welcome.html");
                var body          = ReplaceTokens(emailTemplate, invitation, installation);
                var subject       = ReplaceTokens(_htmlService.GetTitle(emailTemplate), invitation, installation);

                _emailService.SendEmail(newUser.Person.FirstAndLastName, newUser.Person.Email,
                                        installation.Name, ApplicationSettings.Mail.From, subject, body);

                return(new TaskResult <User>(newUser));
            }
            catch (Exception e)
            {
                return(new TaskResult <User>(new TaskException(e)));
            }
        }
Example #23
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed
            }

            // Dispose unmanaged
            if (!IsInvalid)
            {
                try
                {
                    _mainThreadNotification.Set();

                    lock (_eventQueueLock)
                    {
                        Monitor.Pulse(_eventQueueLock);
                    }

                    if (_callbacks != null)
                    {
                        _callbacks.Dispose();
                        _callbacks = null;
                    }

                    PlaylistTrackManager.RemoveAll(this);
                    TrackManager.DisposeAll(this);

                    LinkManager.RemoveAll(this);
                    UserManager.RemoveAll(this);

                    PlaylistContainerManager.RemoveAll(this);
                    PlaylistManager.RemoveAll(this);
                    ContainerPlaylistManager.RemoveAll(this);
                    ArtistManager.RemoveAll();
                    AlbumManager.RemoveAll();

                    SessionManager.Remove(Handle);

                    lock (Spotify.Mutex)
                    {
                        Error error = Error.OK;

                        if (ConnectionState == ConnectionState.LoggedIn)
                        {
                            error = Spotify.sp_session_logout(Handle);
                            Debug.WriteLineIf(error != Error.OK, error.GetMessage());
                        }

                        error = Spotify.sp_session_release(Handle);
                        Debug.WriteLineIf(error != Error.OK, error.GetMessage());
                        Handle = IntPtr.Zero;
                    }
                }
                catch
                {
                    // Ignore
                }
                finally
                {
                    Debug.WriteLine("Session disposed");
                }
            }

            base.Dispose(disposing);
        }