示例#1
0
        public ActionResult Create(TrackModel track)
        {
            if (ModelState.IsValid)
            {
                _repo.Tracks.Add(_m2tMapper.Map(track));
                _repo.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(track);
        }
示例#2
0
        public ActionResult AddTracks(int idp, TrackModel trackid)
        {
            var user = _repo.UsersInfo.Single(u => u.Username.Equals(User.Identity.Name));
            Playlist pl = user.Playlists.Single(p => p.Id == idp);

            //var pl = userdetails.Playlists.First();
            if(pl == null)
                return new HttpStatusCodeResult(409,"There is no playlist with ID="+idp);

            trackid.Id = pl.Tracks.Count +1;
            TrackModel tr = trackid;
               // ((TrackModel)trackid);
            if (tr == null)
            {

                tr.Id = pl.Tracks.Count;
                if (pl.Tracks.Select(tl => tl.Track).Contains(_m2tMapper.Map(tr)))
                    return new HttpStatusCodeResult(409, string.Format("Playlist'{0}' already contain track '{}'.", pl.Name, tr.Name));
            }
            //    return new HttpStatusCodeResult(409, "There is no track with ID=" + trackid);
            //else
            //{

            //    var list = pl.Tracks;
            //    if (list.Select(tl => tl.Track).Contains(tr))
            //        return new HttpStatusCodeResult(409, string.Format("Playlist'{0}' already contain track '{}'.", pl.Name, tr.Name));
            //}
            var o = pl.Tracks.Count();

               if (
               pl.Tracks.Where(
                   x =>
                   trackid.AlbumName != null &&(
                   (x.Track.Name.Contains(trackid.Name) && x.Track.Artist.Contains(trackid.Artist) &&
                    x.Track.Album.Name.Contains(trackid.AlbumName)))).Count()==0)
               {
               pl.Tracks.Add(new TrackList {Order = o + 1, Track = _m2tMapper.Map(tr)});
               _repo.SaveChanges();
               }
               if (utils == null)
               return RedirectToAction("EditTracks", new {id = idp});
               else
               {

               return View("EditTracks",
                           new PlaylistAddTracksModel()
                               {
                                   Playlist = _p2mMapper.Map(pl),
                                   Tracks = _s2tMapper.MapAll(utils.GetLastSearch()).MyExcept(_p2mMapper.Map(pl).Tracks.Values)
                               });
               }
               //new { id=idp , Tracks = utils.GetLastSearch()});
        }
示例#3
0
        public void Create_POST_Redirects_Same_Model_To_GET_If_ModelState_Not_Valid()
        {
            // Arrange
            var controller = new TrackController();
            var track = new TrackModel { Name = "One", Artist = "Metallica" };
            var repo = new Mock<TestDB>();
            controller._repo = repo.Object;
            controller.ModelState.AddModelError("testError", new Exception());

            // Act
            var result = controller.Create(track) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(track, result.Model);
        }
示例#4
0
        public static MvcHtmlString HiddenForAllPublicProperties(this HtmlHelper Html , TrackModel track)
        {
            PropertyInfo[] pis = track.GetType().GetProperties();
            string value="";

            foreach (PropertyInfo p in pis)
            {
                if (p.GetValue(track) == null)
                value += "<input type= \"hidden\" name=" + p.Name + " value=" + p.GetValue(track) + " /> ";
                else
                {
                    value += "<input type= \"hidden\" name=" + p.Name + " value=\"" + p.GetValue(track)+"\""  + " /> ";
                }
            }

            MvcHtmlString htmlString  = new MvcHtmlString(value);

            return htmlString;
        }
示例#5
0
        public void Create_POST_Saves_Track_If_ModelState_Is_Valid()
        {
            // Arrange
            var controller = new TrackController();
            var track = new TrackModel { Name = "One", Artist = "Metallica" };
            var repo = new Mock<TestDB>();

            controller._repo = repo.Object;
            // TODO: Mock data mappers
            controller._m2tMapper = new SpotiChelas.DataMappers.TrackModelToTrackMapper();

            // Act
            var result = controller.Create(track) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("action", result.RouteValues.First().Key);
            Assert.AreEqual("Index", result.RouteValues.First().Value);
            Assert.AreEqual(1, repo.Object.Tracks.Count());
            repo.Verify(x => x.SaveChanges());
        }
示例#6
0
        public ActionResult AddTracks(string username , int idp, TrackModel trackid)
        {
            var user = _repo.UsersInfo.Single(u => u.Username.Equals(username));
            Playlist pl = user.Playlists.Single(p => p.Id == idp);

            //var pl = userdetails.Playlists.First();
            if (pl == null)
                return new HttpStatusCodeResult(409, "There is no playlist with ID=" + idp);

            trackid.Id = pl.Tracks.Count + 1;
            TrackModel tr = trackid;

            var o = pl.Tracks.Count();

            if (
                pl.Tracks.Where(
                    x =>
                    trackid.AlbumName != null && (
                    (x.Track.Name.Contains(trackid.Name) && x.Track.Artist.Contains(trackid.Artist) &&
                     x.Track.Album.Name.Contains(trackid.AlbumName)))).Count() == 0)
            {
                pl.Tracks.Add(new TrackList { Order = o + 1, Track = _m2tMapper.Map(tr) });
                _repo.SaveChanges();
            }
            if (utils == null)
                return RedirectToAction("EditTracks", new { id = idp });
            else
            {

                return View("EditTracks",
                            new PlaylistAddTracksToUserModel()
                            {
                                User = user,
                                Playlist = _p2mMapper.Map(pl),
                                Tracks = _s2tMapper.MapAll(utils.GetLastSearch()).MyExcept(_p2mMapper.Map(pl).Tracks.Values)
                            });
            }
            //new { id=idp , Tracks = utils.GetLastSearch()});
        }
示例#7
0
 public ActionResult Edit(TrackModel track)
 {
     return new HttpStatusCodeResult(501);
 }