Ejemplo n.º 1
0
        public int Save(CD cd)
        {
            var cdEntity = MapCDViewModelToCDEntity(cd);

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

                foreach (var trackModel in cd.Tracks)
                {
                    var trackEntity = new Data.Entities.Track
                    {
                        Id = trackModel.Id,
                        Artist = trackModel.Artist,
                        CD = cdEntity,
                        Length = trackModel.Length,
                        Name = trackModel.Name
                    };

                    cdEntity.Tracks.Add(trackEntity);
                }
            }

            return _cdRepository.Save(cdEntity);
        }
Ejemplo n.º 2
0
        public ActionResult Delete(int id, CD cd)
        {
            try
            {
                _cdModel.Delete(id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(CD cd)
        {
            try
            {
                _cdModel.Save(cd);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int id, CD cd)
        {
            try
            {
                _cdModel.Save(cd);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 5
0
        private static Track MapTrackEntitToTrackModel(Data.Entities.Track trackEntity)
        {
            var cdModel = new CD
            {
                Artist = trackEntity.CD.Artist,
                Genre = trackEntity.CD.Genre,
                Id = trackEntity.CD.Id,
                Title = trackEntity.CD.Title,
                Year = trackEntity.CD.Year
            };

            var trackModel = new Track
            {
                Artist = trackEntity.Artist,
                Id = trackEntity.Id,
                Length = trackEntity.Length,
                Name = trackEntity.Name,
                CD = cdModel
            };

            return trackModel;
        }
Ejemplo n.º 6
0
 private static Data.Entities.CD MapCDViewModelToCDEntity(CD cd)
 {
     return new Data.Entities.CD
     {
         Id = cd.Id,
         Artist = cd.Artist,
         Genre = cd.Genre,
         Title = cd.Title,
         Year = cd.Year
     };
 }
Ejemplo n.º 7
0
        private static CD MapCdEntityToCdViewModel(Data.Entities.CD cdEntity)
        {
            var cd = new CD
            {
                Id = cdEntity.Id,
                Artist = cdEntity.Artist,
                Genre = cdEntity.Genre,
                Title = cdEntity.Title,
                Year = cdEntity.Year,
                Tracks = new List<Track>()
            };

            foreach (var track in cdEntity.Tracks.Select(trackEntity => new Track
            {
                Id = trackEntity.Id,
                Artist = trackEntity.Artist,
                Length = trackEntity.Length,
                Name = trackEntity.Name,
                CD = cd
            }))
            {
                cd.Tracks.Add(track);
            }
            return cd;
        }