Exemple #1
0
        public void Delete(Track track)
        {
            if (_trackRepository == null)
            {
                _trackRepository = new Repository<Data.Entities.Track>();
            }

            _trackRepository.Delete(track.Id);
        }
        public ActionResult Delete(int id, Track track)
        {
            try
            {
                _cdModel.Delete(track);

                return RedirectToAction("Index", new { id = track.CD.Id });
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Create(Track track)
        {
            try
            {
                _cdModel.AddTrackToCd(track.CdId, track);

                return RedirectToAction("Index", new { id=track.CdId });
            }
            catch
            {
                return View();
            }
        }
Exemple #4
0
        public void AddTrackToCd(int id, Track track)
        {
            var cdEntity = _cdRepository.GetById(id);
            var trackEntity = new Data.Entities.Track
            {
                Artist = track.Artist,
                CD = cdEntity,
                Length = track.Length,
                Name = track.Name
            };

            if (cdEntity.Tracks == null)
            {
                cdEntity.Tracks = new List<Data.Entities.Track>();
            }

            cdEntity.Tracks.Add(trackEntity);
            _cdRepository.Save(cdEntity);
        }
Exemple #5
0
        public void Save(Track track)
        {
            var cd = _cdRepository.GetById(track.CD.Id);
            var trackEntity = cd.Tracks.FirstOrDefault(x => x.Id == track.Id);

            if (trackEntity == null)
            {
                throw new NullReferenceException("The track you are trying to update is not on the current CD");
            }

            trackEntity.Artist = track.Artist;
            trackEntity.CD = cd;
            trackEntity.Length = track.Length;
            trackEntity.Name = track.Name;

            //cd.Tracks.Add(trackEntity);
            _cdRepository.Save(cd);
        }
 // GET: Track/Create
 public ActionResult Create(int id)
 {
     var track = new Track {CdId = id};
     return View(track);
 }