Example #1
0
        public ActionResult CloudPlayer()
        {
            var trmservice = new WebService.WCFWebServiceJson();
            var artist = new Artist(); //trmservice.GetArtist(WebSecurity.CurrentUserId);

            ViewBag.ImagePath = MusicManagerBase.StreamingUrl + artist.ProfileImage;
            ViewBag.Genres = WebService.GetAllGenres();

            return View();
        }
        public bool DeleteArtist(Artist artist)
        {
            try
            {
                artistTable.DeleteOnSubmit(artist);
                artistTable.Context.SubmitChanges();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public bool SaveArtist(Artist artist)
        {
            try
            {
                if (artist.ArtistId == 0)
                {
                    artistTable.InsertOnSubmit(artist);
                }
                else
                {
                    artistTable.Context.Refresh(RefreshMode.KeepCurrentValues, artist);
                }

                artistTable.Context.SubmitChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
Example #4
0
        private StringBuilder GetArtistDetailsForDisplay(Artist artist)
        {
            var sb = GetUserDetailsForDisplay(artist);

            return sb;
        }
Example #5
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            // the user instance will be used accross all registration types
            var user = new User()
            {
                //WordpressUserId = Convert.ToInt32(txtWordpressId.Text),
                //CreatedDate = DateTime.Now,
                //UserTypeId = (int)GetUserType()
            };

            switch (GetUserType())
            {
                case User.UserTypeList.Admin:
                    WCFWebServiceJson.RegisterAdmin(user);
                    break;
                case User.UserTypeList.Artist:
                    var artist = new Artist();
                    var artistGenreCollection = (from ListItem listItem in lbGenres.SelectedItems select WCFWebServiceJson.GetGenre(listItem.SelectedValue())).ToList();

                    WCFWebServiceJson.RegisterArtist(artist, artistGenreCollection, null);
                    break;
                case User.UserTypeList.Business:
                    var businessTypeListItem = (ListItem)cbBusinessType.SelectedItem;
                    var businessType = new BusinessType()
                    {
                        BusinessTypeName = businessTypeListItem.ToString(),
                        BusinessTypeId = businessTypeListItem.SelectedValue()
                    };
                    //WCFWebServiceJson.RegisterBusiness(user, businessType, "0.0345749857", "-52.489082309");
                    break;
                default:
                    WCFWebServiceJson.RegisterCustomer(user);
                    break;
            }
        }
        public ActionResult LostPassword(LostPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                MembershipUser user;
                var artistUser = new Artist();
                using (var context = new UsersContext())
                {
                    var userProfile = context.UserProfiles.Where(u => u.UserName == model.Username).FirstOrDefault();

                    if (userProfile != null && !string.IsNullOrEmpty(userProfile.UserName))
                    {
                        user = Membership.GetUser(userProfile.UserName);

                        try
                        {
                            // get local user for their email
                            var trmwebservice = new WebService.WCFWebServiceJson();
                            artistUser = trmwebservice.GetArtist(userProfile.UserId);
                        }
                        catch
                        {
                            ModelState.AddModelError("", "No artist found by that user name.");

                            return View(model);
                        }
                    }
                    else
                    {
                        user = null;
                    }
                }
                if (user != null && artistUser != null)
                {
                    try
                    {
                        // Generate password token that will be used in the email link to authenticate user
                        var token = WebSecurity.GeneratePasswordResetToken(user.UserName);
                        // Generate the html link sent via emailModelState.AddModelError("", "There was an issue sending email: " + e.Message);
                        StringBuilder resetLink = new StringBuilder();
                        resetLink.Append(Url.Action("ResetPassword", "Account", new { rt = token }, "http"));
                        resetLink.AppendLine(Environment.NewLine);
                        resetLink.AppendLine("If the link does not work, please copy and paste it in your browser.");
                        resetLink.AppendLine(Environment.NewLine);
                        resetLink.AppendLine("The team at PlayLift Ltd.");

                        // Email stuff
                        string subject = "PlayLift - Reset your password for " + artistUser.ArtistName;
                        string body = "Reset password link: " + resetLink;
                        string from = "*****@*****.**";

                        MailMessage message = new MailMessage(from, artistUser.Email);
                        message.Subject = subject;
                        message.Body = body;
                        SmtpClient client = new SmtpClient("auth.smtp.1and1.co.uk");
                        client.Credentials = new NetworkCredential("*****@*****.**", "trm_info");

                        // Attempt to send the email
                        try
                        {
                            client.Send(message);
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", "There was an issue sending email: " + e.Message);
                        }
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "We cannot reset your password because: " + ex.Message + " If you have registered with a social network, please reset your password with the provider.");
                    }

                }
                else // Email not found
                {
                    /* Note: You may not want to provide the following information
                    * since it gives an intruder information as to whether a
                    * certain email address is registered with this website or not.
                    * If you're really concerned about privacy, you may want to
                    * forward to the same "Success" page regardless whether an
                    * user was found or not. This is only for illustration purposes.
                    */
                    ModelState.AddModelError("", "No user found by that user name.");

                    return View(model);
                }
            }

            /* You may want to send the user to a "Success" page upon the successful
            * sending of the reset email link. Right now, if we are 100% successful
            * nothing happens on the page. :P
            */
            return RedirectToAction("ResetLinkSent");
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

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

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (UsersContext db = new UsersContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        var artist = new Artist
                        {
                            UserName = model.UserName,
                            UserType = DomainModel.Entities.User.UserTypeList.Artist,
                            TermsAndConditionsAccepted = model.TermsAndConditions,
                        };

                        var trmwebservice = new WebService.WCFWebServiceJson();
                        if (trmwebservice.RegisterArtistSocial(artist, provider, providerUserId))
                        {
                            OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);
                            return RedirectToAction("RegisterSuccess", "Account");
                        }
                        else
                        {
                            ModelState.AddModelError("ArtistRegistrationError", "There was an issue registering you. If the problemt persists, please contact us at [email protected]");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        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);
        }
        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);
        }
        public List<Album> GetArtistAlbums(Artist artist)
        {
            var artistAlbumCollection = SqlArtistAlbumRepository.ArtistAlbum.Where(x => x.UserId == artist.UserId).ToList();
            var albumCollection = artistAlbumCollection.Select(album => SqlAlbumRepository.Album.FirstOrDefault(x => x.AlbumId == album.AlbumId)).ToList();

            foreach (var album in albumCollection)
            {
                var albumGenreCollection = SqlAlbumGenreRepository.AlbumGenre.Where(x => album != null && x.AlbumId == album.AlbumId);
                foreach (var genre in albumGenreCollection)
                {
                    album.GenreCollection = SqlGenreRepository.Genre.Where(x => x.GenreId == genre.GenreId).ToList();
                }
            }

            return albumCollection;
        }
        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);
        }
        public bool DeleteArtistAlbum(Album album, Artist artist)
        {
            using (var tranScope = new TransactionScope())
            {
                var artistAlbum =
                    SqlArtistAlbumRepository.ArtistAlbum.FirstOrDefault(
                        x => x.AlbumId == album.AlbumId && x.UserId == artist.UserId);

                try
                {
                    if (SqlArtistAlbumRepository.DeleteArtistAlbum(artistAlbum))
                    {
                        if (SqlAlbumRepository.DeleteAlbum(album))
                        {
                            tranScope.Complete();
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                catch
                {
                    return false;
                }
            }
        }
 private bool SaveArtist(Artist artist)
 {
     try
     {
         return SqlArtistRepository.SaveArtist(artist);
     }
     catch (Exception ex)
     {
         util.ErrorNotification(ex);
         throw;
     }
 }
        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);
        }
        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;
        }
        // Albums
        public PartialViewResult _Albums(List<Album> albums, Artist artist)
        {
            if (albums == null)
            {
                return PartialView(new List<Album>());
            }

            ViewBag.ArtistId = artist.ArtistId;
            ViewBag.ArtistName = artist.ArtistName;

            return PartialView(albums);
        }