示例#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 PartialViewResult ArtistAlbums()
        {
            var trmservice = new WebService.WCFWebServiceJson();
            var artist = trmservice.GetArtist(WebSecurity.CurrentUserId);
            ViewBag.ArtistAlbums = trmservice.GetArtistAlbums(artist);
            ViewBag.ArtistName = artist.ArtistName;

            return PartialView();
        }
示例#3
0
        public ActionResult ArtistSongs(int userId)
        {
            var trmservice = new WebService.WCFWebServiceJson();
            var artist = trmservice.GetArtist(userId);
            ViewBag.ArtistAlbums = trmservice.GetArtistAlbums(artist);
            ViewBag.UserId = userId;

            return View();
        }
示例#4
0
        public string EditAlbum(string form, string fileStream, string fileName, string fileType)
        {
            var result = "The album was not created. Please try again. If the problem persists, please contact us at [email protected]";
            var formCollection = form.Split('&');
            var trmservice = new WebService.WCFWebServiceJson();
            var artist = trmservice.GetArtist(WebSecurity.CurrentUserId);
            var util = new Utilities();
            var localFile = Path.Combine(MusicManagerBase.LocalTempDestinationPath, fileName);

            if (!string.IsNullOrEmpty(fileStream))
            {
                byte[] bytes = Convert.FromBase64String(fileStream);
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    Image image = Image.FromStream(ms);
                    image.Save(localFile);
                }
            }

            // populate the list of albums for this artist to be displayed in the management section
            ViewBag.ArtistAlbums = trmservice.GetArtistAlbums(artist);

            if (!string.IsNullOrEmpty(fileName) || !string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumCoverPath")))
            {
                // Attempt to save the album
                try
                {
                    var albumGenreList = new List<Genre>();

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

                    var albumId = 0;
                    if (!string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumId")) && Convert.ToInt32(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumId")) > 0)
                    {
                        albumId = Convert.ToInt32(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumId"));
                        trmservice.UpdateAlbumGenreCollection(albumId, albumGenreList);
                    }

                    // if editing, if no image is uploaded, use the existing path
                    var albumCover = string.Empty;

                    if (string.IsNullOrEmpty(fileName))
                    {
                        albumCover = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumCoverPath");
                    }
                    else
                    {
                        albumCover = util.RemoveSpaces(artist.ArtistName) + "/" + util.RemoveSpaces(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumTitle")) + "/" + fileName;
                    }

                    var releaseDate = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumReleaseDate").ToString().Replace("%2F", "/");

                    var album = new Album
                    {
                        AlbumId = albumId,
                        AlbumTitle = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumTitle"),
                        AlbumProducer = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumProducer"),
                        AlbumLabel = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumLabel"),
                        AlbumReleaseDate = Convert.ToDateTime(releaseDate),
                        AlbumCover = albumCover,
                        GenreCollection = albumGenreList,
                        CreatedDate = DateTime.Now
                    };

                    // link the album to the artist and save it
                    trmservice.SaveArtistAlbum(album, artist, localFile);

                    result = "You have successfully uploaded the album " + album.AlbumTitle;
                }
                catch (MembershipCreateUserException e)
                {
                    result = ErrorCodeToString(e.StatusCode);
                }
            }
            else
            {
                result = "Please select an album cover";
            }

            // delete the temp file
            if (System.IO.File.Exists(localFile))
            {
                System.IO.File.Delete(localFile);
            }
            return result;
        }
示例#5
0
        // Artist management
        // GET: /Account/ArtistSongs
        public PartialViewResult ArtistSongs(int albumId)
        {
            var trmservice = new WebService.WCFWebServiceJson();
            var artist = trmservice.GetArtist(WebSecurity.CurrentUserId);
            ViewBag.ArtistAlbums = trmservice.GetArtistAlbums(artist);
            ViewBag.AlbumId = albumId;

            return PartialView();
        }