예제 #1
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);
        }