コード例 #1
0
        public SongGetRequest Insert(SongInsertRequest song)
        {
            var entity = _mapper.Map <Song>(song);

            _context.Song.Add(entity);
            _context.SaveChanges();

            return(_mapper.Map <SongGetRequest>(_context.Song.Last()));
        }
コード例 #2
0
        public SongGetRequest Update(int id, SongInsertRequest obj)
        {
            var entity = _context.Song.Find(id);

            if (entity != null)
            {
                _context.Song.Attach(entity);
                _context.Song.Update(entity);

                entity.Title   = obj.Title;
                entity.Text    = obj.Text;
                entity.AlbumId = obj.AlbumId;

                _context.SaveChanges();
                return(_mapper.Map <SongGetRequest>(entity));
            }
            return(null);
        }
コード例 #3
0
        private async void btnSaveEditedSong_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                SongInsertRequest req = new SongInsertRequest();
                req.Title   = txtName.Text;
                req.Text    = txtLyrics.Text;
                req.AlbumId = (int)cmbAlbum.SelectedValue;

                await _songService.Update <SongGetRequest>(_songId, req);

                Helper.HelperMethods.CloseAllForms();
                frmSong frm = new frmSong();
                frm.MdiParent   = Application.OpenForms["frmIndex"];
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
        }
コード例 #4
0
        private async void btnFinish_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                SongInsertRequest req = new SongInsertRequest();
                req.Title   = txtName.Text;
                req.Text    = txtLyrics.Text;
                req.AlbumId = (int)cmbAlbum.SelectedValue;

                await _songService.Insert <SongInsertRequest>(req, "AddSong");

                this.Close();
                frmSong frm = new frmSong();
                frm.Show();
                frm.MdiParent   = Application.OpenForms["frmIndex"];
                frm.WindowState = FormWindowState.Maximized;
            }
        }
コード例 #5
0
 /* methods */
 public AddSongViewModel()
 {
     Title   = "Add song";
     SongReq = new SongInsertRequest();
 }
コード例 #6
0
 public ActionResult <SongGetRequest> Update(int id, SongInsertRequest song)
 {
     return(_songService.Update(id, song));
 }
コード例 #7
0
 public ActionResult <SongGetRequest> Insert(SongInsertRequest song)
 {
     return(_songService.Insert(song));
 }