Ejemplo n.º 1
0
        public ActionResult AddSong(SongViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_db.Songs.FirstOrDefault(I => I.Title == viewModel.Title) == null)
                {
                    var song = new Song();
                    song.Title = viewModel.Title;
                    song.Writer = viewModel.Writer;
                    song.Genre = viewModel.Genre;
                    song.Tone = viewModel.Tone;
                    song.Rhythm = viewModel.Rhythm;
                    song.Body = viewModel.Body;
                    song.CreatedBy = User.Identity.Name;

                    _db.AddSong(song);
                    _db.Save();

                    return RedirectToAction("index", "home");
                }
                else
                {
                    ViewBag.Message = "Bản nhạc này đã có rồi.";
                }
            }

            return View(viewModel);
        }
Ejemplo n.º 2
0
        List<SongViewModel> GetData()
        {
            List<SongViewModel> model = new List<SongViewModel>();

            var result =
                from s in _db.Songs
                orderby s.ID descending
                select new { s.ID, s.Title };

            foreach (var item in result)
            {
                SongViewModel song = new SongViewModel();
                song.ID = item.ID;
                song.Title = item.Title;
                model.Add(song);
            }

            return model;
        }
Ejemplo n.º 3
0
 public ActionResult AddSong()
 {
     var model = new SongViewModel();
     return View(model);
 }