예제 #1
0
        public List <dynamic> RegisterFull(FormDataCollection formData)
        {
            List <string> errors   = new List <string>();
            List <string> response = new List <string>();

            if (formData != null)
            {
                string name            = formData.Get("name");
                string surname         = formData.Get("surname");
                string password        = formData.Get("password");
                string confirmPassword = formData.Get("confirmPassword");
                string email           = formData.Get("email");
                string country         = formData.Get("country");
                string state           = formData.Get("state");
                string city            = formData.Get("city");
                string mobile          = formData.Get("mobile");
                string promo           = formData.Get("promo");
                string membershipType  = formData.Get("membershipType");
                string tnc             = formData.Get("TermsAndConditions");

                // Validation section - cascade errors
                if (string.IsNullOrEmpty(name))
                {
                    errors.Add("Name is required.");
                }

                if (string.IsNullOrEmpty(surname))
                {
                    errors.Add("Surname is required.");
                }

                if (string.IsNullOrEmpty(password))
                {
                    errors.Add("Password is required.");
                }

                if (string.IsNullOrEmpty(confirmPassword))
                {
                    errors.Add("Confirm Password is required.");
                }
                else
                {
                    if (password.Trim() != confirmPassword.Trim())
                    {
                        errors.Add("Passwords don't match");
                    }
                }

                if (string.IsNullOrEmpty(email))
                {
                    errors.Add("Email is required.");
                }
                else
                {
                    // check for existing.
                }

                if (string.IsNullOrEmpty(country))
                {
                    errors.Add("Country is required.");
                }
                else
                {
                    // validate country ID
                }

                if (string.IsNullOrEmpty(membershipType))
                {
                    errors.Add("Membership Type is required.");
                }
                else
                {
                    // validate membership type
                }

                if (string.IsNullOrEmpty(tnc))
                {
                    errors.Add("Terms and Conditions required.");
                }
                else
                {
                    if (tnc.Trim() != "1")
                    {
                        errors.Add("Terms and Conditions required.");
                    }
                }

                promo  = (string.IsNullOrEmpty(promo)) ? null : promo;
                city   = (string.IsNullOrEmpty(city)) ? "" : city;
                state  = (string.IsNullOrEmpty(state)) ? "" : state;
                mobile = (string.IsNullOrEmpty(mobile)) ? "" : mobile;

                if (errors.Count > 0)
                {
                    return(errors.ToList <dynamic>());
                }

                // No apparent errors, continue creation.
                int countryID = Convert.ToInt32(country.Trim());
                int?cityID    = null;
                int?stateID   = null;

                if (!(string.IsNullOrEmpty(city)))
                {
                    cityID = Convert.ToInt32(city.Trim());
                }

                if (!(string.IsNullOrEmpty(state)))
                {
                    stateID = Convert.ToInt32(state.Trim());
                }

                int    membershipTypeID = Convert.ToInt32(membershipType.Trim());
                int?   OwnerID          = getOwner(countryID, stateID, cityID, promo);
                string MobileNumber     = "";
                if (!string.IsNullOrEmpty(mobile))
                {
                    MobileNumber = Regex.Replace(mobile, @"\s+", "");
                }

                AccountHelper    accountHelper = new AccountHelper();
                AccountService   service       = new AccountService(db, UserManager);
                ApplicationUser  user;
                AccountViewModel avm = new AccountViewModel();
                avm.Email     = email.Trim();
                avm.CountryID = countryID;
                avm.CityID    = cityID;
                avm.FirstName = name.Trim();
                avm.LastName  = surname.Trim();
                avm.MemberSubscriptionType = membershipTypeID;
                avm.ownerID            = OwnerID;
                avm.Password           = password.Trim();
                avm.ConfirmPassword    = confirmPassword.Trim();
                avm.MobileNumber       = MobileNumber;
                avm.PromoCode          = (string.IsNullOrEmpty(promo)) ? "" : promo.Trim();
                avm.StateID            = stateID;
                avm.TermsAndConditions = Convert.ToBoolean(Convert.ToInt32(tnc.Trim()));
                IEnumerable <string> Ierrors;
                System.Web.Http.Routing.UrlHelper urlHelper = new System.Web.Http.Routing.UrlHelper(Request);

                if (service.createUser(accountHelper.ToMember(avm), avm.Password, out user, out Ierrors, urlHelper))
                {
                    GameDao gd = new GameDao(db);
                    gd.AddMemberToGame(user);
                    // Do user sign-in
                    string AuthToken = this.Authenticate(avm.Email, avm.Password);
                    // Get Member ID

                    Member member = service.findMember(avm.Email);
                    if (member == null)
                    {
                        errors.Add("Member not generated");
                        return(errors.ToList <dynamic>());
                    }

                    response.Add("AuthorizationToken::" + AuthToken);
                    response.Add("MemberID::" + member.MemberID);
                }
                if (Ierrors.Count() > 0)
                {
                    return(Ierrors.ToList <dynamic>());
                }
            }
            return(response.ToList <dynamic>());
        }