コード例 #1
0
        public ActionResult Create(PlaylistViewModel viewModel, HttpPostedFileBase avatarImage)
        {
            Playlist playlist;
            string path = null;

            if(String.IsNullOrEmpty(viewModel.Name) || viewModel.Name == " ")
            {
                ModelState.AddModelError("Name", "You need to fill in a name for your playlist");
                return View(viewModel);
            }

            var user = userManager.ReadUser(User != null ? User.Identity.Name : testName);

            if (avatarImage != null && avatarImage.ContentLength > 0)
            {
                var bannerFileName = Path.GetFileName(avatarImage.FileName);
                path = FileHelper.NextAvailableFilename(Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["PlaylistImgPath"]), bannerFileName));
                avatarImage.SaveAs(path);
                path = Path.GetFileName(path);
            }

            var keyAlreadyInUser = playlistManager.ReadPlaylistByKey(viewModel.Key);

            if(keyAlreadyInUser != null || viewModel.Key == null)
            {
                ModelState.AddModelError("Key", "The key value is already in use");
                return View(viewModel);
            }


            try {
                if (viewModel.OrganisationId != 0)
                {
                    playlist = playlistManager.CreatePlaylistForOrganisation(viewModel.Name, viewModel.Description, viewModel.Key, viewModel.MaximumVotesPerUser, true, path, user, viewModel.OrganisationId);
                }
                else
                {
                    playlist = playlistManager.CreatePlaylistForUser(viewModel.Name, viewModel.Description, viewModel.Key, viewModel.MaximumVotesPerUser, true, path, user);
                }
                return RedirectToAction("View", new { key = playlist.Key });
            }
            catch (System.Exception e)
            {
                ModelState.AddModelError("","Something went wrong");
                return View(viewModel);
            }
            

        }
コード例 #2
0
 public ActionResult Edit(long id)
 {
     var playlist = playlistManager.ReadPlaylist(id);
     var model = new PlaylistViewModel()
     {
         Name = playlist.Name,
         Description = playlist.Description,
         ImageUrl = playlist.ImageUrl,
         Key = playlist.Key,
         MaximumVotesPerUser = playlist.MaximumVotesPerUser
     };
     return PartialView(model);
 }
コード例 #3
0
        public ActionResult Edit(long id, PlaylistViewModel model, HttpPostedFileBase avatarImage)
        {
            try
            {
                var playlist = playlistManager.ReadPlaylist(id);

                if (String.IsNullOrEmpty(model.Name) || model.Name == " ")
                {
                    ModelState.AddModelError("Name", "You need to fill in a name for your playlist");
                    return View(model);
                }
                var keyAlreadyInUse = playlistManager.ReadPlaylistByKey(model.Key);

                if (keyAlreadyInUse != null || String.IsNullOrEmpty(model.Key))
                {
                    ModelState.AddModelError("Key", "The key value is already in use");
                    return View(model);
                }
                playlist.Name = model.Name;
                playlist.Description = model.Description;
                playlist.Key = model.Key;
                playlist.ImageUrl = model.ImageUrl;
                playlist.MaximumVotesPerUser = model.MaximumVotesPerUser;
                string path = null;

                if (avatarImage != null && avatarImage.ContentLength > 0)
                {
                    var bannerFileName = Path.GetFileName(avatarImage.FileName);
                    path = FileHelper.NextAvailableFilename(Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["PlaylistImgPath"]), bannerFileName));
                    avatarImage.SaveAs(path);
                    path = Path.GetFileName(path);
                }
                playlist.ImageUrl = path;

                playlistManager.UpdatePlaylist(playlist);

                return RedirectToAction("Portal", "Home");
            }
            catch
            {
                return new HttpStatusCodeResult(400);
            }
        }
コード例 #4
0
        public void CreatePlaylist()
        {
            PlaylistViewModel playlistViewModel = new PlaylistViewModel()
            {
                MaximumVotesPerUser = 4,
                Name = "Awesome party",
                Key = "123ABC"
            };

            controller.Create(playlistViewModel, null);
            Playlist playlist = DbInitializer.CreatePlaylistManager().ReadPlaylist("Awesome party");
            Assert.AreEqual(playlist.Active, true);

        }