public ICommandResult Handle(CreateSongCommand command) { var singerQuery = _singerRepository.GetById(command.SingerId); var albumQuery = _albumRepository.GetById(command.AlbumId); Name singerName = new Name(singerQuery.FirstName, singerQuery.LastName); Singer singer = new Singer(singerQuery.Id, singerName, singerQuery.Nationality, singerQuery.About, singerQuery.Image); Album album = new Album(albumQuery.Id, albumQuery.Title, null, null, albumQuery.Image); Song song = new Song(command.Title, singer, album, command.Url, command.PublishedDate); AddNotifications(song.Notifications); if (Invalid) { return(new CommandResult(false, MessagesUtil.FormFail, Notifications)); } bool result = _repository.Create(song); if (!result) { return(new CommandResult(false, MessagesUtil.CreateError, Notifications)); } return(new CommandResult(true, MessagesUtil.CreatedSuccess)); }
private static void CreateAndAddVotingCandidate(int number, int numberOfVotes, IVotingCandidateRepository votingCandidateRepository, IVoteRepository voteRepository, ISongRepository songRepository) { var song = songRepository.Create(); song.Title = "SongRepositoryTests" + number; song.DurationInSeconds = 120; song.FileName = "SongRepositoryTests.mp3"; songRepository.Add(song); var votingCandidate = votingCandidateRepository.Create(); votingCandidate.SongId = song.Id; votingCandidate.Song = song; votingCandidate.DisplayOrder = number; votingCandidateRepository.Add(votingCandidate); foreach (var index in Enumerable.Range(0, numberOfVotes)) { var vote = voteRepository.Create(); vote.VotingCandidateId = votingCandidate.Id; vote.VotingCandidate = votingCandidate; vote.UserIdentifier = Guid.NewGuid(); voteRepository.Add(vote); } }
private Song ImportSong(string songFileName, FileInfo coverImageFile, DateTimeOffset importDate, ISongRepository songRepository, IImageService imageService) { using (var songTagFile = TagLib.File.Create(songFileName)) { var tagValidationResults = ValidateTags(songTagFile); if (tagValidationResults.Any()) { _logger.LogWarning("File {0} is invalid. {1}", songFileName, string.Join(", ", tagValidationResults)); return(null); } var songFileInfo = new System.IO.FileInfo(songFileName); var relativeSongFileName = Path.Combine(songFileInfo.Directory.Name, songFileInfo.Name); var song = songRepository.GetByFileNameOrDefault(relativeSongFileName); if (song == null) { song = songRepository.Create(); songRepository.Add(song); } song.Map( title: songTagFile.Tag.Title, album: songTagFile.Tag.Album, artist: songTagFile.Tag.FirstPerformer, coverImageFile: coverImageFile, duration: songTagFile.Properties.Duration, fileName: relativeSongFileName, imageService: imageService); song.LastImportDate = importDate; return(song); } }
public IActionResult Post([FromBody] Song song) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _songRepository.Create(song); return(StatusCode(StatusCodes.Status201Created)); }
public void Create_Adds_New_Song() { var song = new Song(); var otherSong = new Song(); repo.Create(song); repo.Received().Create(song); repo.DidNotReceive().Create(otherSong); }
private static Song CreateAndAddSong(int number, ISongRepository songRepository) { var song = songRepository.Create(); song.Title = "SongRepositoryTests" + number; song.DurationInSeconds = 120; song.FileName = "SongRepositoryTests.mp3"; songRepository.Add(song); return(song); }
public Song Post(SongDTO value) { Console.Write("fitness class id: " + value.FitnessClassId); Song model = new Song() { Name = value.Name, Singer = value.Singer, Bpm = value.Bpm, FitnessClassId = value.FitnessClassId }; return(ISongRepository.Create(model)); }
public ActionResult Create(Song s) { if (ModelState.IsValid) { try { var song = _songRepository.Create(s); return(RedirectToAction("Details", new { id = song.Id })); } catch (Exception ex) { return(View(s)); } } return(RedirectToAction("Index")); }
public void Can_Create_a_Song() { var pass = true; var newSong = new Song(); //gets added to testRepo var wrongSong = new Song(); //doesn't get added to testRepo //This is based off NSubstitute website, No Assert Needed! (Received, instead) testRepo.Create(newSong); if (!pass) //Change var pass to false to see this fail - it works { testRepo.Received().Create(wrongSong); } if (pass) { testRepo.Received().Create(newSong); } }
public ActionResult Create(Song song) { repo.Create(song); return(RedirectToAction("Index")); }
public ActionResult Create(Song song) { songRepo.Create(song); return(RedirectToAction("../Album/Details/" + song.AlbumId)); }
public void Create(Song song) { _songRepository.Create(song); }
public bool Insert(Song song) { _repository.Create(song); return(_repository.SaveChanges()); }
public ActionResult Create(Song song) { repo.Create(song); return(RedirectToAction("Details/" + song.AlbumId, "Album")); }