Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void btnSaveSong_Click(object sender, EventArgs e)
        {
            var util = new Utilities();
            var songGenreCollection = (from ListItem listItem in lbSongGenres.SelectedItems select WCFWebServiceJson.GetGenre(listItem.SelectedValue())).ToList();
            var albumCollection = (from ListItem listItem in lbSongAlbums.SelectedItems select WCFWebServiceJson.GetArtistAlbumDetails(listItem.SelectedValue())).ToList();

            var song = new Song()
            {
                AlbumCollection = albumCollection,
                CreatedDate = DateTime.Now,
                GenreCollection = songGenreCollection,
                SongComposer = txtSongComposer.Text,
                SongReleaseDate = Convert.ToDateTime(dtpSongReleaseDate.Text),
                SongTitle = txtSongTitle.Text
            };

            foreach (var album in albumCollection)
            {
                if (WCFWebServiceJson.UploadSong(song, lblSelectedFile.Text, "mp3", txtSongWordpressId.Text + "/" + util.RemoveSpaces(album.AlbumTitle) + "/"))
                {
                    txtSongsResults.Text = song.SongTitle + @" has been saved successfully!";
                }
                else
                {
                    txtSongsResults.Text = @"There was a problem saving the song: " + song.SongTitle;
                }
            }
        }
Exemplo n.º 3
0
        public string EditSong(string form, string fileStream, string fileName, string fileType)
        {
            var result = "The song was not uploaded. 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))
                {
                    using (FileStream file = new FileStream(localFile, FileMode.Create, System.IO.FileAccess.Write))
                    {
                        ms.Read(bytes, 0, (int)ms.Length);
                        file.Write(bytes, 0, bytes.Length);
                        ms.Close();
                    }
                }
            }

            if (!string.IsNullOrEmpty(fileName) || !string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "MediaAssetPath")))
            {
                // Attempt to save the song
                try
                {
                    var albumCollection = new List<Album>();
                    var songGenreList = new List<Genre>();

                    foreach (var formItem in formCollection)
                    {
                        if (formItem.ToString().StartsWith("genre"))
                        {
                            songGenreList.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"));
                    }

                    var songId = 0;
                    if (!string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "SongId")) && Convert.ToInt32(MusicManagerBase.ReturnFormItemValue(formCollection, "SongId")) > 0)
                    {
                        songId = Convert.ToInt32(MusicManagerBase.ReturnFormItemValue(formCollection, "SongId"));
                    }

                    var album = trmservice.GetArtistAlbumDetails(albumId);
                    albumCollection.Add(album);

                    var mediaFileFolder = string.Empty;
                    var mediaFileLocation = string.Empty;

                    if (!string.IsNullOrEmpty(fileName))
                    {
                        mediaFileLocation = localFile;
                        mediaFileFolder = util.RemoveSpaces(artist.ArtistName) + "/" + util.RemoveSpaces(album.AlbumTitle) + "/";
                    }

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

                    var song = new Song()
                    {
                        AlbumCollection = albumCollection,
                        CreatedDate = DateTime.Now,
                        GenreCollection = songGenreList,
                        SongComposer = MusicManagerBase.ReturnFormItemValue(formCollection, "SongComposer"),
                        SongId = songId,
                        SongReleaseDate = Convert.ToDateTime(releaseDate),
                        SongTitle = MusicManagerBase.ReturnFormItemValue(formCollection, "SongTitle"),
                        PRS = MusicManagerBase.ReturnFormBooleanValue(formCollection, "PRS")
                    };

                    // upload and save the song
                    if (trmservice.UploadSong(song, mediaFileLocation, "mp3", mediaFileFolder))
                    {
                        result = "The song \"" + song.SongTitle + "\" has been uploaded successfully.";
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    result = ErrorCodeToString(e.StatusCode);
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
            }
            else
            {
                result = "Please select a media file to upload";
            }

            return result;
        }
Exemplo n.º 4
0
        public string ArtistDetails(string form, string fileStream, string fileName, string fileType)
        {
            var result = "Your details have not been updated. 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 profileImage = string.Empty;
            var localFile = Path.Combine(MusicManagerBase.LocalTempDestinationPath, fileName);

            if (!string.IsNullOrEmpty(fileStream))
            {
                byte[] bytes = Convert.FromBase64String(fileStream);
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    using (FileStream file = new FileStream(localFile, FileMode.Create, System.IO.FileAccess.Write))
                    {
                        ms.Read(bytes, 0, (int)ms.Length);
                        file.Write(bytes, 0, bytes.Length);
                        ms.Close();
                    }
                }
            }

            if (!string.IsNullOrEmpty(fileName) || !string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "ProfileImagePath")))
            {
                // Attempt to upate the user
                try
                {
                    if (string.IsNullOrEmpty(fileName))
                    {
                        profileImage = MusicManagerBase.ReturnFormItemValue(formCollection, "ProfileImagePath");
                    }
                    else
                    {
                        profileImage = util.RemoveSpaces(MusicManagerBase.ReturnFormItemValue(formCollection, "ArtistName")) + "/" + fileName;
                    }

                    artist.ProfileImage = profileImage;
                    artist.ArtistName = MusicManagerBase.ReturnFormItemValue(formCollection, "ArtistName");
                    artist.Email = MusicManagerBase.ReturnFormItemValue(formCollection, "Email");
                    artist.Facebook = MusicManagerBase.ReturnFormItemValue(formCollection, "Facebook");
                    artist.MySpace = MusicManagerBase.ReturnFormItemValue(formCollection, "MySpace");
                    artist.SoundCloud = MusicManagerBase.ReturnFormItemValue(formCollection, "SoundCloud");
                    artist.Twitter = MusicManagerBase.ReturnFormItemValue(formCollection, "Twitter");
                    artist.Website = MusicManagerBase.ReturnFormItemValue(formCollection, "Website");
                    artist.PRS = MusicManagerBase.ReturnFormBooleanValue(formCollection, "PRS");
                    artist.CreativeCommonsLicence = MusicManagerBase.ReturnFormBooleanValue(formCollection, "CreativeCommonsLicence");
                    artist.Bio = MusicManagerBase.ReturnFormItemValue(formCollection, "Bio");

                    var artistGenreList = new List<Genre>();

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

                    if (trmservice.UpdateArtist(artist, artistGenreList, localFile))
                    {
                        result = "You have successfully updated your details";
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    result = ErrorCodeToString(e.StatusCode);
                }
            }
            else
            {
                result = "Please select a profile image";
            }

            return result;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        public ActionResult RegisterArtist(ArtistRegisterModel model, FormCollection form)
        {
            ViewBag.Register = "Register as an artist or band";
            ViewBag.RegisterAction = "Register";
            ViewBag.Message = "Artist.";

            if (!model.TermsAndConditions)
            {
                ModelState.AddModelError("TermsAndConditions", "You must agree to the terms and conditions to register.");
            }

            if (ModelState.IsValid)
            {
                if (model.ProfileImage != null)
                {
                    // Attempt to register the user
                    try
                    {
                        var trmservice = new WebService.WCFWebServiceJson();
                        var util = new Utilities();

                        var artist = new Artist
                        {
                            ProfileImage = util.RemoveSpaces(model.ArtistName) + "/" + model.ProfileImage.FileName,
                            ArtistName = model.ArtistName,
                            UserName = model.UserName,
                            Password = model.Password,
                            UserType = DomainModel.Entities.User.UserTypeList.Artist,
                            Email = model.Email,
                            Facebook = model.Facebook,
                            MySpace = model.MySpace,
                            SoundCloud = model.SoundCloud,
                            Twitter = model.Twitter,
                            Website = model.Website,
                            TermsAndConditionsAccepted = model.TermsAndConditions,
                            PRS = model.PRS,
                            CreativeCommonsLicence = model.CreativeCommonsLicence,
                            Bio = model.Bio,
                            CountyCityId = model.CountyCityId
                        };

                        var artistGenreList = new List<Genre>();

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

                        if (trmservice.RegisterArtist(artist, artistGenreList, model.ProfileImage))
                        {
                            WebSecurity.Login(model.UserName, model.Password);
                            return RedirectToAction("RegisterSuccess", "Account");
                        }
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("Error registering artist", ErrorCodeToString(e.StatusCode));
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("Generic Error", e.ToString());
                    }
                }
                else
                {
                    ModelState.AddModelError("MissingProfileImage", "Please select a profile image.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 7
0
        public ActionResult RegisterBusiness(BusinessRegisterModel model)
        {
            ViewBag.Register = "Register as a business";
            ViewBag.RegisterAction = "Register";
            ViewBag.Message = "Business.";

            if (!model.TermsAndConditions)
            {
                ModelState.AddModelError("TermsAndConditions", "You must agree to the terms and conditions to register.");
            }

            if (ModelState.IsValid)
            {
                if (model.Logo != null)
                {
                    // Attempt to register the user
                    try
                    {
                        var trmservice = new WebService.WCFWebServiceJson();
                        var util = new Utilities();

                        var business = new BusinessUser
                        {
                            Logo= util.RemoveSpaces(model.BusinessName) + "/" + model.Logo.FileName,
                            UserName = model.UserName,
                            Password = model.Password,
                            UserType = DomainModel.Entities.User.UserTypeList.Business,
                            BusinessName = model.BusinessName,
                            BusinessType = trmservice.GetAllBusinessTypes().Where(x => x.BusinessTypeId == model.BusinessType).FirstOrDefault(),
                            BusinessTypeId = model.BusinessType,
                            Address1 = model.Address1,
                            Address2 = model.Address2,
                            City = model.City,
                            PostCode = model.PostCode,
                            Country = model.Country,
                            TermsAndConditionsAccepted = model.TermsAndConditions,
                            CreatedDate = DateTime.Now
                        };

                        if (trmservice.RegisterBusiness(business, model.Logo))
                        {
                            WebSecurity.Login(model.UserName, model.Password);
                            return RedirectToAction("RegisterBusinessSuccess", "Account");
                        }
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("Error registering business", ErrorCodeToString(e.StatusCode));
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("Generic Error", e.ToString());
                    }
                }
                else
                {
                    ModelState.AddModelError("MissingProfileImage", "Please select a profile image.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 8
0
        public bool RegisterArtistSocial(Artist artist, string provider, string providerUserId)
        {
            var util = new Utilities();
            bool isRegistered;

            using (var tranScope = new TransactionScope())
            {
                try
                {
                    OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, artist.UserName);
                    Roles.AddUserToRole(artist.UserName, "Artist");

                    // if the user is saved successfully it will return a userId which is always greater than 0
                    artist.UserId = WebSecurity.GetUserId(artist.UserName);

                    // save an artist instance of this user
                    isRegistered = SaveArtist(artist);

                    tranScope.Complete();
                }
                catch (MembershipCreateUserException ex)
                {
                    util.ErrorNotification(ex);
                    throw;
                }
                catch (Exception ex)
                {
                    util.ErrorNotification(ex);
                    throw;
                }
            }

            return (artist.UserId > 0 && isRegistered);
        }
Exemplo n.º 9
0
        public bool RegisterArtist(Artist artist, List<Genre> genreCollection, HttpPostedFileBase sourceFile)
        {
            var util = new Utilities();
            bool isRegistered;

            using (var tranScope = new TransactionScope())
            {
                try
                {
                    // if the user is saved successfully it will return a userId which is always greater than 0
                    WebSecurity.CreateUserAndAccount(artist.UserName, artist.Password);
                    Roles.AddUserToRole(artist.UserName, artist.UserType.ToString());
                    artist.UserId = WebSecurity.GetUserId(artist.UserName);

                    // first save an artist instance of this user
                    isRegistered = SaveArtist(artist);

                    if (isRegistered)
                    {
                        // now create an account for this user
                        isRegistered = SaveUserAccount(artist, Account.AccountTypeList.artist);

                        foreach (var genre in genreCollection)
                        {
                            isRegistered = SqlArtistGenreRepository.SaveArtistGenre(new ArtistGenre()
                                {
                                    UserId = artist.UserId,
                                    GenreId = genre.GenreId
                                });

                            if (!isRegistered)
                            {
                                return false;
                            }
                        }

                        // save file locally to upload it
                        if (!UploadFileToS3(SaveFileLocally(sourceFile), util.RemoveSpaces(artist.ArtistName) + "/", "stream"))
                        {
                            return false;
                        }

                        tranScope.Complete();
                    }
                }
                catch (MembershipCreateUserException ex)
                {
                    util.ErrorNotification(ex);
                    throw;
                }
                catch (Exception ex)
                {
                    util.ErrorNotification(ex);
                    throw;
                }
            }

            return (artist.UserId > 0 && isRegistered);
        }
Exemplo n.º 10
0
        private string ReplaceIllegalCharacters(string input)
        {
            var util = new Utilities();
            input = util.RemoveSpaces(input);

            return input.Replace(" ", "_").Replace("/", "-").Replace(@"\", "-").Replace("&", "").Replace("'", "").Replace("@", "").Replace("*", "");
        }
Exemplo n.º 11
0
        public bool UpdateArtist(Artist artist, List<Genre> genreCollection, string sourceFile)
        {
            var util = new Utilities();
            bool isRegistered;

            using (var tranScope = new TransactionScope())
            {
                try
                {
                    // if the user is saved successfully it will return a userId which is always greater than 0
                    isRegistered = SaveArtist(artist);

                    if (isRegistered)
                    {
                        if (UpdateArtistGenreCollection(artist.UserId, genreCollection))
                        {
                            // if there is a file, save it locally to upload it
                            if (sourceFile != null && !string.IsNullOrEmpty(Path.GetExtension(sourceFile)))
                            {
                                if (!UploadFileToS3(sourceFile, util.RemoveSpaces(artist.ArtistName) + "/", "stream"))
                                {
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            return false;
                        }

                        tranScope.Complete();
                    }
                }
                catch
                {
                    return false;
                }
            }

            return (artist.UserId > 0 && isRegistered);
        }
Exemplo n.º 12
0
        public bool SaveArtistAlbum(Album album, Artist artist, string sourceFile)
        {
            using (var tranScope = new TransactionScope())
            {
                try
                {
                    var albumId = SqlAlbumRepository.SaveAlbum(album);

                    if (albumId > 0)
                    {
                        if (SaveAlbumGenreCollection(albumId, album.GenreCollection))
                        {
                            var util = new Utilities();
                            var artistAlbum = new ArtistAlbum()
                                 {
                                     AlbumId = albumId,
                                     UserId = artist.UserId
                                 };

                            if (UploadFileToS3(sourceFile, util.RemoveSpaces(artist.ArtistName) + "/" + util.RemoveSpaces(album.AlbumTitle) + "/", "stream"))
                            {
                                if (SqlArtistAlbumRepository.SaveArtistAlbum(artistAlbum))
                                {
                                    tranScope.Complete();
                                    return true;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    return false;
                }
            }

            return false;
        }