public async Task <ServiceResult> Add(AlbumResultModel model)
        {
            var serviceResult = new ServiceResult();

            var songsResult = model.Songs == null || model.Songs.Count == 0 ? new DatabaseManyResult <SongModel>()
            {
                Success = true, Entities = null
            } : await _songRepository.GetMany(model.Songs, 0, 50);

            if (!songsResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = songsResult.Message;
                return(serviceResult);
            }
            var artistsResult = model.Artists == null || model.Artists.Count == 0 ? new DatabaseManyResult <ArtistModel>()
            {
                Success = true, Entities = null
            } : await _artistRepository.GetMany(model.Artists, 0, 50);

            if (!artistsResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = artistsResult.Message;
                return(serviceResult);
            }
            var genresResult = model.Genres == null || model.Genres.Count == 0 ? new DatabaseManyResult <GenreModel>()
            {
                Success = true, Entities = null
            } : await _genreRepository.GetMany(model.Genres, 0, 50);

            if (!genresResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = genresResult.Message;
                return(serviceResult);
            }


            var modelObject = new AlbumModel()
            {
                Id      = model.Id,
                Name    = model.Name,
                ArtId   = model.ArtId,
                Songs   = songsResult.Entities,
                Artists = artistsResult.Entities,
                Genres  = genresResult.Entities
            };

            var result = await _albumRepository.Add(modelObject);

            serviceResult.Success = result.Success;
            if (!result.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = result.Message;
            }

            return(serviceResult);
        }
Example #2
0
        public async Task <IActionResult> CreateAlbum(CreateAlbumDto albumToCreate)
        {
            int userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // Check if user exceeded album limit
            if (_limitSettings.Value.MaxAlbums != 0 && await _albumRepo.GetAlbumCount(userId) >= _limitSettings.Value.MaxAlbums)
            {
                return(BadRequest($"You have reached the maximum album limit of {_limitSettings.Value.MaxAlbums.ToString()}"));
            }

            var album = new Album(albumToCreate.IsPublic, userId, albumToCreate.Name);

            _albumRepo.Add(album);

            if (!await _albumRepo.SaveAll())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Failed at saving album" }));
            }

            var albumToReturn = _mapper.Map <AlbumToReturnDto>(album);

            if (album.IsPublic)
            {
                return(CreatedAtRoute("GetAlbum", new { controller = "Album", albumId = album.Id }, albumToReturn));
            }
            return(CreatedAtRoute("GetAlbumPrivate", new { controller = "Album", albumId = album.Id }, albumToReturn));
        }
Example #3
0
        public CreateAlbumResponse CreateAlbum(CreateAlbumRequest request)
        {
            var response = new CreateAlbumResponse();

            var album = new Album
            {
                Genre       = _genreRepository.FindBy(request.GenreId),
                Artist      = _artistRepository.FindBy(request.ArtistId),
                Title       = request.Title,
                Description = request.Description,
                Price       = request.Price,
                AlbumArtUrl = request.AlbumArtUrl
            };

            ThrowExceptionIfAlbumIsInvalid(album);

            _albumRepository.Add(album);

            _uow.Commit();

            MvcSiteMapProvider.SiteMaps.ReleaseSiteMap();

            response.Album = album.ConvertToAlbumView();

            return(response);
        }
Example #4
0
        public void AddAlbum()
        {
            var album = new Album();

            album.Title    = "Test Album";
            album.ArtistId = 70;
            albumRepository.Add(album);
            dbContext.SaveChanges();

            Assert.IsTrue(album.AlbumId > 0, "OK");
        }
        public ActionResult Create([FromForm] Album album)
        {
            try
            {
                _repository.Add(album);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(new BadRequestResult());
            }
        }
Example #6
0
        public ActionResult CreateAlbum(AlbumVM albumVM)
        {
            Album album = new Album();

            album.Name        = albumVM.Name;
            album.Description = albumVM.Description;
            album.Guid        = Guid.NewGuid();
            album.Path        = MVCManager.Controller.Main.DefaultAlbumsPath;
            Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, album.Path, album.Guid.ToString()));
            _albumRepository.Add(album);
            _albumRepository.UnitOfWork.SaveChanges();
            return(RedirectToAction(MVCManager.Controller.Main.Album, MVCManager.Controller.Main.Name, new { _albumRepository.GetAll().LastOrDefault().Id }));
        }
        public async Task <AlbumViewModel> Handle(CreateAlbumCommand request, CancellationToken cancellationToken)
        {
            var myId  = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var album = new Domain.AggregatesModel.AlbumAggregate.Album(request.Name, myId);

            _albumRepository.Add(album);

            if (await _albumRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken))
            {
                return(await _albumQueries.GetAlbumAsync(album.Id));
            }

            throw new ApplicationException("操作失败");
        }
 public Album UpdateAlbum(Album album)
 {
     return(ExecuteFaultHandledOperation(() => { IAlbumRepository albumRepository =
                                                     _dataRepositoryFactory.GetDataRepository <IAlbumRepository>();
                                                 Album updatedEntity = null;
                                                 if (album.AlbumId == 0)
                                                 {
                                                     updatedEntity = albumRepository.Add(album);
                                                 }
                                                 else
                                                 {
                                                     updatedEntity = albumRepository.Update(album);
                                                 }
                                                 return updatedEntity; }));
 }
Example #9
0
        public Album CreateAlbum(string title, string description, string username)
        {
            User user   = _userRepository.GetSingleByUsername(username);
            var  UserID = user.Id;
            var  album  = new Album()
            {
                Title       = title,
                Description = description,
                DateCreated = DateTime.Now,
                User_ID     = user.Id
            };

            _albumRepository.Add(album);
            _albumRepository.Commit();
            return(album);
        }
Example #10
0
        public void Save(IAlbum album, out bool success)
        {
            Checks.Argument.IsNotNull(album, "album");

            success = false;

            if (null == _repo.FindByAlbumId(album.AlbumId))
            {
                try
                {
                    _repo.Add(album);
                    success = true;
                }
                catch (Exception ex)
                {
                    success = false;
                }
            }
        }
Example #11
0
        public InsertDataAlbumResponse InsertDataAlbum(InsertDataAlbumRequest request)
        {
            InsertDataAlbumResponse response = new InsertDataAlbumResponse();

            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    _albumRepo.Add(request.Album);
                    transScope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

            return(response);
        }
Example #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start!");

            var genre = new Genre("Dubstep");

            _genreRepository.Add(genre);
            Console.WriteLine("Genre created");

            var country = new Country("Germany");

            _countryRepository.Add(country);
            Console.WriteLine("Country created");

            var userData = new CommonUserData("Egop", "Bird", "Tit", DateTime.Today);

            _commonUserDataRepository.Add(userData);
            Console.WriteLine("CommonUserData created");

            var userLibrary = new UserLibrary(new List <Album>(), new List <Playlist>());

            _userLibraryRepository.Add(userLibrary);
            Console.WriteLine("UserLibrary created");

            var art = new Art("image.jpg");

            _artRepository.Add(art);
            Console.WriteLine("Art created");

            var playlist = new Playlist("test playlist", "test description", art, userLibrary,
                                        new List <TrackToPlaylist>());

            _playlistRepository.Add(playlist);
            Console.WriteLine("Playlist created");

            userLibrary.Playlists.Add(playlist);
            _userLibraryRepository.Update(userLibrary);

            Console.WriteLine("Playlist added to UserLibrary");

            var distributorData = new DistributorData("test distributor", country, new List <Album>(),
                                                      new List <ArtistToDistributor>());

            _distributorDataRepository.Add(distributorData);
            Console.WriteLine("DistributorData created");

            var album = new Album("test album", DateTime.Now, art, genre, distributorData, new List <Track>());

            _albumRepository.Add(album);
            Console.WriteLine("Album created");

            var track = new Track("Terror Drums", "test.mp3", 0, false, album, new List <TrackToPlaylist>());

            track.Playlists.Add(new TrackToPlaylist(track, playlist));
            _trackRepository.Add(track);
            Console.WriteLine("Track created");

            //foreach (var genre in _genreRepository.GetAll())
            //{
            //    Console.WriteLine(genre.Title);
            //}
            Console.ReadKey();
        }
Example #13
0
 public IActionResult createAlbum(Album album)
 { //Geef AterlierDTO en controleer de HTTPPut
     _albumRepository.Add(album);
     _albumRepository.saveChanges();
     return(Ok());
 }
Example #14
0
        public int PublishProjectById(int projectId, ProjectReviewViewModel reviewModel)
        {
            var projectToUpdate = _projectMasterRepository.GetById(projectId);
            int albumId         = 0;

            if (projectToUpdate != null)
            {
                //   1.1. Update project status
                projectToUpdate.statuscode      = "PUBLISHED";
                projectToUpdate.updatedby       = "User";
                projectToUpdate.updatedon       = DateTime.Now;
                projectToUpdate.reviewedby      = "User";
                projectToUpdate.reviewedok      = true;
                projectToUpdate.reviewedon      = DateTime.Now;
                projectToUpdate.reviewedcomment = reviewModel.ReviewComment;

                _projectMasterRepository.Update(projectToUpdate);

                var label       = _organizationLabelRepository.GetById(reviewModel.LabelId);
                var isrcSeries  = _organizationIsrcSeriesRepository.GetById(reviewModel.IsrcSeriesId);
                var currentDate = DateTime.Now;

                //   1.2. Create media_product_package
                var productPackage = new media_product_package
                {
                    albumtitle           = projectToUpdate.projectname,
                    albumid              = 0,
                    physicallocation     = "",
                    labelid              = reviewModel.LabelId,
                    cataloguenumber      = "",
                    releasetypecode      = "0",
                    countryofproduction  = label.countrycode,
                    countryofpublication = label.countrycode,
                    releasedate          = currentDate,
                    packagestatusid      = 4,
                    numberoftracks       = _projectTrackRepository.GetMany(pt => pt.projectid == projectId).Count(),
                    formattypeid         = 2,
                    comment              = reviewModel.ReviewComment,
                    updatedby            = "User",
                    updatedon            = currentDate,
                    createdby            = "User",
                    createdon            = currentDate,
                    mainartistid         = projectToUpdate.mainartistid
                };
                _albumRepository.Add(productPackage);

                _unitOfWork.Commit();

                albumId = productPackage.id;

                var projectTracks  = _projectTrackRepository.GetMany(pt => pt.projectid == projectId).ToList();
                var lastUsedNumber = isrcSeries.isrc_lastusednumber;

                foreach (var track in projectTracks)
                {
                    string isrc;

                    if (string.IsNullOrEmpty(track.isrc))
                    {
                        isrc = IsrcHelper.GenerateIsrcNumber(isrcSeries.isrc_countrypart,
                                                             isrcSeries.isrc_organizationpart,
                                                             isrcSeries.isrc_lastusedyear, ++lastUsedNumber);
                    }
                    else
                    {
                        isrc = track.isrc;
                    }

                    // Update track isrc as well.
                    track.isrc = isrc;
                    _projectTrackRepository.Update(track);

                    int recordingId;

                    if (track.recordingid != null && track.recordingid != -1)
                    {
                        recordingId = track.recordingid.Value;
                    }
                    else
                    {
                        //   1.3. Create media_recording (s)
                        var recording = new media_recording
                        {
                            isrc                 = isrc,
                            recordingtitle       = track.trackname,
                            workingtitle         = track.trackname,
                            recordingcountrycode = label.countrycode,
                            statusid             = 4,
                            updatedby            = "User",
                            updatedon            = currentDate,
                            createdby            = "User",
                            createdon            = currentDate,
                            recordingdate        = track.createdon,
                            duration             = track.duration,
                            mainartist           = projectToUpdate.mainartistid,
                            markedfordeletion    = false,
                            projecttrackid       = track.id
                        };

                        _mediaRecordingRepository.Add(recording);

                        _unitOfWork.Commit();

                        recordingId = recording.id;
                    }

                    //   1.4. Create media_product (s)
                    _songRepository.Add(new media_product
                    {
                        isrc                = isrc,
                        recordingid         = recordingId,
                        title               = track.trackname,
                        tracknumber         = track.trackorder,
                        sidenumber          = 1,
                        labelid             = reviewModel.LabelId,
                        cataloguenumber     = "",
                        mediaproducttypeid  = 1,
                        packageid           = albumId,
                        releasedate         = currentDate,
                        countryofproduction = label.countrycode,
                        statusid            = 4,
                        updatedby           = "User",
                        updatedon           = currentDate,
                        createdby           = "User",
                        createdon           = currentDate,
                        is_deleted          = false
                    });

                    var projectTrackArtists = _projectTrackArtistRepository.GetMany(p => p.projecttrackid == track.id).ToList();

                    //   1.5. Add to recording_party
                    projectTrackArtists.ForEach(pta => _recordingPartyRepository.Add(new recording_party
                    {
                        recordingid       = recordingId,
                        partyrealid       = pta.partyrealid,
                        rolecode          = pta.rolecode,
                        instrumentcode    = pta.instrumentcode,
                        artistpseudonymid = pta.artistpseudonymid,
                        updatedby         = "User",
                        updatedon         = currentDate,
                        createdby         = "User",
                        createdon         = currentDate,
                        status            = 2
                    }));
                }

                isrcSeries.updatedon            = currentDate;
                isrcSeries.updatedby            = "User";
                isrcSeries.isrc_lastusednumber += 100;
                isrcSeries.isrc_lastusedyear    = DateTime.Now.Year;

                _organizationIsrcSeriesRepository.Update(isrcSeries);

                //   1.6. Commit changes
                _unitOfWork.Commit();
            }

            return(albumId);
        }
Example #15
0
        public int CreateAlbum(AlbumCreationViewModel album)
        {
            int albumId;

            var label       = _organizationLabelRepository.GetById(album.PublisherLabelId);
            var isrcSeries  = _organizationIsrcSeriesRepository.GetById(album.Publisher.IsrcSeriesId);
            var currentDate = DateTime.Now;

            var productPackage = new media_product_package
            {
                albumtitle           = album.BasicInfo.AlbumTitle,
                albumid              = 0,
                physicallocation     = "",
                labelid              = album.PublisherLabelId,
                cataloguenumber      = "",
                releasetypecode      = "0",
                countryofproduction  = label.countrycode,
                countryofpublication = label.countrycode,
                releasedate          = currentDate,
                packagestatusid      = 4,
                numberoftracks       = album.BasicInfo.NumberOfTracks,
                formattypeid         = 2,
                comment              = album.ReviewComment,
                updatedby            = "User",
                updatedon            = currentDate,
                createdby            = "User",
                createdon            = currentDate,
                mainartistid         = album.BasicInfo.MainArtistId
            };

            _albumRepository.Add(productPackage);

            _unitOfWork.Commit();

            albumId = productPackage.id;

            foreach (var song in album.Songs)
            {
                // If newly created song has already been created with the same isrc.
                if (song.Id == -1 && _mediaRecordingRepository.Get(m => m.isrc == song.Isrc) != null)
                {
                    throw new DuplicateNameException("Isrc provided does already exist.");
                }

                int recordingId;

                if (song.Id == -1)
                {
                    //   1.3. Create media_recording (s)
                    var recording = new media_recording
                    {
                        isrc                 = song.Isrc,
                        recordingtitle       = song.Name,
                        workingtitle         = song.Name,
                        recordingcountrycode = label.countrycode,
                        statusid             = 4,
                        updatedby            = "User",
                        updatedon            = currentDate,
                        createdby            = "User",
                        createdon            = currentDate,
                        recordingdate        = song.RecordingDate,
                        duration             = song.Length,
                        mainartist           = album.BasicInfo.MainArtistId,
                        markedfordeletion    = false
                    };

                    _mediaRecordingRepository.Add(recording);
                    _unitOfWork.Commit();

                    recordingId = recording.id;
                }
                else
                {
                    recordingId = song.Id;
                }

                //   1.4. Create media_product (s)
                _songRepository.Add(new media_product
                {
                    isrc                = song.Isrc,
                    recordingid         = recordingId,
                    title               = song.Name,
                    tracknumber         = song.Number,
                    sidenumber          = 1,
                    labelid             = album.PublisherLabelId,
                    cataloguenumber     = "",
                    mediaproducttypeid  = 1,
                    packageid           = albumId,
                    releasedate         = currentDate,
                    countryofproduction = label.countrycode,
                    statusid            = 4,
                    updatedby           = "User",
                    updatedon           = currentDate,
                    createdby           = "User",
                    createdon           = currentDate,
                    is_deleted          = false
                });

                //   1.5. Add to recording_party
                song.Performers.ForEach(performer => _recordingPartyRepository.Add(new recording_party
                {
                    recordingid    = recordingId,
                    partyrealid    = performer.Id,
                    rolecode       = performer.Role.RoleCode,
                    instrumentcode = performer.Instrument.IdCode,
                    updatedby      = "User",
                    updatedon      = currentDate,
                    createdby      = "User",
                    createdon      = currentDate,
                    status         = 2
                }));
            }

            isrcSeries.updatedon            = currentDate;
            isrcSeries.updatedby            = "User";
            isrcSeries.isrc_lastusednumber += 100;
            isrcSeries.isrc_lastusedyear    = DateTime.Now.Year;

            _organizationIsrcSeriesRepository.Update(isrcSeries);

            //   1.6. Commit changes
            _unitOfWork.Commit();

            return(albumId);
        }
Example #16
0
 public void AddAlbum(Album album)
 {
     _albumRepository.Add(album);
 }
Example #17
0
        public Album AddAlbum(Album newAlbum)
        {
            Album createdAlbum = _albumRepository.Add(newAlbum);

            return(createdAlbum);
        }