public bool Create(CreateSongDto creationInfo) { try { var song = new Song { Name = creationInfo.Name, Genre = creationInfo.Genre, ReleaseDate = creationInfo.ReleaseDate, ReleaseStage = creationInfo.ReleaseStage, TrackNumber = creationInfo.TrackNumber, MusicVideoLink = creationInfo.MusicVideoLink, Lyrics = creationInfo.Lyrics, ArtistId = creationInfo.ArtistId, ApprovalStatus = ApprovalStatus.Pending }; this.context.Songs.Add(song); this.context.SaveChanges(); return(true); } catch { return(false); } }
private CreateSongDto CollectFormData() { CreateSongDto dto = new CreateSongDto(); try { dto.Name = txb_songname.Text.Trim(); dto.AlbumId = (cbx_album.SelectedItem as AlbumDto).Id; dto.Composer = txb_composer.Text.Trim(); dto.Bytes = Convert.ToInt32(txb_bytes.Text.Trim()); dto.Miliseconds = Convert.ToInt32(txb_milisec.Text.Trim()); dto.Price = Convert.ToDecimal(txb_unitprice.Text.Trim()); dto.MediaId = (cbx_mediaType.SelectedItem as MediaTypeDto).Id; dto.GenreId = (cbx_genre.SelectedItem as GenreDto).Id; } catch (Exception exp) { MessageBox.Show(exp.Message); } //Playlist var selectedPlaylists = playlistCheckbox.CheckedItems; foreach (var playlist in selectedPlaylists) { dto.PlaylistIDs.Add((playlist as PlaylistDto).Id); } return(dto); }
public void Create_IncreasesCount() { // Arrange var context = this.ServiceProvider.GetRequiredService <WmipDbContext>(); var songsService = new SongsService(context); var creationInfo = new CreateSongDto() { Name = "songs" }; // Act songsService.Create(creationInfo); //Assert Assert.Single(context.Songs); }
private void btn_updatesongf2_Click(object sender, EventArgs e) { CreateSongDto dto = CollectFormData(); dto.SongId = id; try { var operation = new CreateSongOperation(dto); operation.Execute(); MessageBox.Show("Uspesan update!"); this.Dispose(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private void button1_Click(object sender, EventArgs e) { CreateSongDto dto = CollectFormData(); try { var operation = new CreateSongOperation(dto); operation.Execute(); MessageBox.Show("Uspesan unos!"); txb_songname.Text = ""; txb_composer.Text = ""; cbx_mediaType.SelectedItem = 1; cbx_genre.SelectedItem = 1; cbx_album.SelectedItem = 1; txb_unitprice.Text = ""; } catch (Exception exp) { MessageBox.Show(exp.Message); } }