示例#1
0
        public PartialViewResult ArtistAlbums(ArtistAlbumModel model, FormCollection form)
        {
            var trmservice = new WebService.WCFWebServiceJson();
            var artist = trmservice.GetArtist(WebSecurity.CurrentUserId);
            var util = new Utilities();

            ViewBag.ArtistAlbums = trmservice.GetArtistAlbums(artist);

            if (ModelState.IsValid)
            {
                if (model.AlbumCover != null)
                {
                    // Attempt to save the album
                    try
                    {
                        var albumGenreList = new List<Genre>();

                        foreach (var formItem in form)
                        {
                            if (formItem.ToString().StartsWith("genre"))
                            {
                                albumGenreList.Add(new Genre
                                {
                                    GenreId = GetGenreId(formItem.ToString()),
                                    GenreName = GetGenreName(formItem.ToString())
                                });
                            }
                        }

                        var album = new Album
                        {
                            AlbumTitle = model.AlbumTitle,
                            AlbumProducer = model.AlbumProducer,
                            AlbumLabel = model.AlbumLabel,
                            AlbumReleaseDate = model.AlbumReleaseDate,
                            AlbumCover = util.RemoveSpaces(artist.ArtistName) + "/" + util.RemoveSpaces(model.AlbumTitle) + "/" + model.AlbumCover.FileName,
                            GenreCollection = albumGenreList,
                            CreatedDate = DateTime.Now
                        };

                        // link the album to the artist and save it
                        trmservice.SaveArtistAlbum(album, artist, album.AlbumCover);
                        ViewBag.StatusMessage = "The album \"" + album.AlbumTitle + "\" has been uploaded successfully.";
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                    }
                }
                else
                {
                    ModelState.AddModelError("MissingAlbumCover", "Please select an album cover");
                }
            }

            // If we got this far, something failed, redisplay form
            return PartialView(model);
        }
示例#2
0
        public ActionResult EditAlbum(int albumId)
        {
            var artistAlbumModel = new ArtistAlbumModel();

            if (albumId > 0)
            {
                var trmservice = new WebService.WCFWebServiceJson();
                var artist = trmservice.GetArtist(WebSecurity.CurrentUserId);
                var albumDetails = trmservice.GetArtistAlbumDetails(albumId);

                artistAlbumModel.AlbumId = albumDetails.AlbumId;
                artistAlbumModel.AlbumCoverPath = albumDetails.AlbumCover;
                artistAlbumModel.AlbumLabel = albumDetails.AlbumLabel;
                artistAlbumModel.AlbumProducer = albumDetails.AlbumProducer;
                artistAlbumModel.AlbumReleaseDate = albumDetails.AlbumReleaseDate;
                artistAlbumModel.AlbumTitle = albumDetails.AlbumTitle;
                artistAlbumModel.GenreCollection = albumDetails.GenreCollection;
            }

            return View(artistAlbumModel);
        }