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

            _trackRepository.Delete(track.Id);
        }
示例#2
0
        public ActionResult Delete(int id, Track track)
        {
            try
            {
                _cdModel.Delete(track);

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

                return RedirectToAction("Index", new { id=track.CdId });
            }
            catch
            {
                return View();
            }
        }
示例#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);
        }
示例#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);
        }
示例#6
0
 // GET: Track/Create
 public ActionResult Create(int id)
 {
     var track = new Track {CdId = id};
     return View(track);
 }