Exemple #1
0
        public PartialViewResult GetListSimilar(string name)
        {
            var                     nameForRequest = name.Replace(" ", "+");
            List <Similar>          listSimilar    = new List <Similar>();
            List <SimilarViewModel> listModel      = new List <SimilarViewModel>();
            var                     listSimInDb    = _similarService.GetAll().Where(a => a.ArtistId == _artistService.GetAll().FirstOrDefault(b => b.Name == name).Id);

            if (listSimInDb.Count() != 0)
            {
                foreach (Similar s in listSimInDb)
                {
                    var modelSim = new SimilarViewModel()
                    {
                        Name  = s.Name,
                        Photo = s.Photo
                    };
                    listModel.Add(modelSim);
                }
                return(PartialView(listModel));
            }
            listSimilar = _similarService.GetListSimilar(nameForRequest);
            foreach (Similar sim in listSimilar)
            {
                sim.ArtistId = _artistService.Get(name).Id;
                _similarService.Create(sim);
                var model = new SimilarViewModel()
                {
                    Name  = sim.Name,
                    Photo = sim.Photo
                };
                listModel.Add(model);
            }
            return(PartialView(listModel));
        }
            public Task <IEnumerable <ArtistResponseDTO> > Handle(GetArtistEntriesRequest request, CancellationToken cancellationToken)
            {
                IEnumerable <IArtistEntry> artistEntries = _artistService.Get();

                IEnumerable <ArtistResponseDTO> artistEntryDtos = artistEntries.Select(artistEntry => artistEntry.Adapt <ArtistResponseDTO>() with
                {
                    DateEntries = artistEntry.DateEntryIDs.Select(dateEntry => _datesService.Get(dateEntry).Adapt <DateEntryDTO>()).ToList()
                });
            public Task <bool> Handle(DeleteArtistEntryRequest request, CancellationToken cancellationToken)
            {
                IArtistEntry artist = _artistService.Get(request.ArtistEntryId);

                foreach (string dateId in artist.DateEntryIDs)
                {
                    _datesService.Remove(dateId);
                }

                return(Task.FromResult(_artistService.Remove(request.ArtistEntryId)));
            }
            public Task <bool> Handle(DeleteDateEntryRequest request, CancellationToken cancellationToken)
            {
                IArtistEntry artist       = _artistService.Get(request.ArtistId);
                bool         removeResult = _datesService.Remove(request.DateId);

                artist.DateEntryIDs.Remove(request.DateId);

                if (artist.DateEntryIDs.Count > 0)
                {
                    _artistService.Update(request.ArtistId, artist);

                    return(Task.FromResult(removeResult));
                }

                return(Task.FromResult(_artistService.Remove(artist.Id)));
            }
            public Task <Unit> Handle(AddArtistEntryRequest request, CancellationToken cancellationToken)
            {
                IArtistEntry         artistEntry  = _artistService.Get().SingleOrDefault(entry => entry.ArtistName == request.ArtistRequest.ArtistName);
                IEnumerable <string> dateEntryIDs = CreateDateEntries(request.ArtistRequest.DateEntryRequests);

                if (artistEntry == null)
                {
                    artistEntry = _artistService.Create(string.Empty, request.ArtistRequest.ArtistName, dateEntryIDs);
                }
                else
                {
                    artistEntry.AddDateEntries(dateEntryIDs);
                    _artistService.Update(artistEntry.Id, artistEntry);
                }

                return(Task.FromResult(Unit.Value));
            }
Exemple #6
0
        public void Search()
        {
            string[] filenames = Directory.GetFiles("D:/WEB_Onion/OAA.Web/wwwroot/tracks/", "*.mp3", SearchOption.AllDirectories);
            foreach (var link in filenames)
            {
                // nameTrack-nameArtist.mp3
                var nameTrack  = "";
                var nameArtist = "";
                var splited    = link.Split("-");
                nameTrack  = splited[0].Split("/")[5];
                nameArtist = splited[1].Replace(".mp3", "");

                var linkT = "http://localhost:52527/tracks/" + nameTrack + "-" + nameArtist + ".mp3";

                var nameT = nameTrack.Replace(" ", "+");
                var nameA = nameArtist.Replace(" ", "+");

                if (artistService.GetAll().Where(a => a.Name == nameArtist).Count() == 0)
                {
                    AddArtistToDb(nameArtist);
                }

                var   nameAlbum = trackService.GetAlbumTrackName(nameA, nameT);
                Album album     = albumService.GetAll().Where(a => a.NameArtist == nameArtist).FirstOrDefault(b => b.Name == nameAlbum);

                if (album == null)
                {
                    Album alb = albumService.GetAlbum(nameArtist, nameAlbum);
                    alb.ArtistId = artistService.Get(nameArtist).Id;
                    albumService.Create(alb);
                }

                if (trackService.GetAll().Where(a => a.Name == nameTrack).FirstOrDefault(b => b.NameAlbum == nameAlbum) != null)
                {
                    AddLinkToDb(nameTrack, nameArtist, linkT);
                }
                else
                {
                    Track track = trackService.AddTrackFromLast(nameTrack, nameArtist, linkT);
                    track.AlbumId   = albumService.GetAll().Where(a => a.Name == nameAlbum).FirstOrDefault(b => b.NameArtist == nameArtist).Id;
                    track.NameAlbum = nameAlbum;
                    trackService.Create(track);
                }
            }
        }
Exemple #7
0
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            var mapper = new ApiArtistServerModelMapper();
            ApplicationDbContext         context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IArtistService               service = testServer.Host.Services.GetService(typeof(IArtistService)) as IArtistService;
            ApiArtistServerResponseModel model   = await service.Get(1);

            ApiArtistClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", "B", "B", "B", "B", "B");

            UpdateResponse <ApiArtistClientResponseModel> updateResponse = await client.ArtistUpdateAsync(model.Id, request);

            context.Entry(context.Set <Artist>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Artist>().ToList()[0].AspNetUserId.Should().Be("B");
            context.Set <Artist>().ToList()[0].Bio.Should().Be("B");
            context.Set <Artist>().ToList()[0].ExternalId.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"));
            context.Set <Artist>().ToList()[0].Facebook.Should().Be("B");
            context.Set <Artist>().ToList()[0].Name.Should().Be("B");
            context.Set <Artist>().ToList()[0].SoundCloud.Should().Be("B");
            context.Set <Artist>().ToList()[0].Twitter.Should().Be("B");
            context.Set <Artist>().ToList()[0].Venmo.Should().Be("B");
            context.Set <Artist>().ToList()[0].Website.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.AspNetUserId.Should().Be("B");
            updateResponse.Record.Bio.Should().Be("B");
            updateResponse.Record.ExternalId.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"));
            updateResponse.Record.Facebook.Should().Be("B");
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.SoundCloud.Should().Be("B");
            updateResponse.Record.Twitter.Should().Be("B");
            updateResponse.Record.Venmo.Should().Be("B");
            updateResponse.Record.Website.Should().Be("B");
        }
Exemple #8
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer           testServer = new TestServer(builder);
            var                  client     = new ApiClient(testServer.CreateClient());
            ApplicationDbContext context    = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IArtistService service = testServer.Host.Services.GetService(typeof(IArtistService)) as IArtistService;
            var            model   = new ApiArtistServerRequestModel();

            model.SetProperties("B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", "B", "B", "B", "B", "B");
            CreateResponse <ApiArtistServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.ArtistDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiArtistServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Exemple #9
0
        public IHttpActionResult GetById(int id)
        {
            var artist = artistService.Get(id);

            return(Ok(artist));
        }
Exemple #10
0
        public HttpResponseMessage GetArtist(Guid id)
        {
            var artist = service.Get(id);

            return(Request.CreateResponse(HttpStatusCode.OK, artist));
        }
Exemple #11
0
        public async Task <JsonResult> Get()
        {
            var artists = await _artistService.Get();

            return(new JsonResult(artists));
        }
Exemple #12
0
 public Artist Get(int id, bool @readonly = false)
 {
     return(_service.Get(id, @readonly));
 }
 public async Task <IActionResult> Update(int id)
 {
     return(View(
                await _artistService.Get(id)
                ));
 }
Exemple #14
0
        public async Task <IHttpActionResult> Get(string id)
        {
            var result = await _artistService.Get(id);

            return(ServiceResult(result));
        }
        public Result Create(CreateMoovieModel moovie)
        {
            var moovieId = GetId(moovie.Name);

            if (moovieId != null && moovieId != Guid.Empty)
            {
                return new Result()
                       {
                           Status  = false,
                           Message = "Filme já existente."
                       }
            }
            ;

            var directorId = _artistService.Get(moovie.DirectorName, Data.Enums.Artist.Type.Director);

            if (directorId == null || directorId == Guid.Empty)
            {
                return new Result()
                       {
                           Status  = false,
                           Message = "Diretor não encontrado."
                       }
            }
            ;

            var countryId = _countryService.Get(moovie.CountryName);

            if (countryId == null || countryId == Guid.Empty)
            {
                return new Result()
                       {
                           Status  = false,
                           Message = "Nacionalidade não encontrada."
                       }
            }
            ;

            var genreId = _genreService.Get(moovie.GenreName);

            if (genreId == null || genreId == Guid.Empty)
            {
                return new Result()
                       {
                           Status  = false,
                           Message = "Gênero de filme não encontrado."
                       }
            }
            ;

            var newMoovieDatabaseModel = new Moovie()
            {
                Id           = Guid.NewGuid(),
                Name         = moovie.Name,
                ReleaseDate  = moovie.ReleaseDate,
                DirectorId   = (Guid)directorId,
                CountryId    = (Guid)countryId,
                GenreId      = (Guid)genreId,
                Observations = moovie.Observations
            };

            _unitOfWork.RepositoryBase.Add(newMoovieDatabaseModel);
            _unitOfWork.Commit();

            return(new Result()
            {
                Status = true,
                Message = "Filme adicionado com sucesso!",
                Object = moovie
            });
        }