예제 #1
0
        private string GetSupplierAddress(AddressModel addressModel, out bool isDefaultSupplierAddress)
        {
            isDefaultSupplierAddress = false;
            //Address ID given to all suppliers after decision not to forse suppliers to enter address
            var supplierAddressDefault = Convert.ToInt32(ConfigurationManager.AppSettings["DefaultSupplierAddressId"]);

            if (addressModel.Id == supplierAddressDefault)
            {
                isDefaultSupplierAddress = true;
            }

            return isDefaultSupplierAddress
                ? "Address not entered"
                : ViewModelHelper.GetUserAddress(addressModel);
        }
예제 #2
0
        public AddressModel GetAddressById(int addressId)
        {
            using (var context = new greenMoneyEntities())
            {
                var address = context.Addresses.FirstOrDefault(x => x.Id == addressId);
                if (address != null)
                {
                    var model = new AddressModel();
                    Utils.CopyProperties(address, model);

                    return model;
                }
            }
            return null;
        }
예제 #3
0
        public ActionResult RegisterAddress(RegisterAccountViewModel model)
        {
            if (ModelState.IsValid)
            {

                AddressModel addressModelFind = new AddressModel();

                // find new user's address
                AddressModel address = new UserService().FindMatchingAdressModel(
                    unitNumber: model.UnitNumber,
                    streetNumber: model.StreetNumber,
                    streetName: model.StreetName,
                    streetType: model.StreetType,
                    suburb: model.Suburb,
                    postcode: null
                    );

                //Address exists in database
                if (address != null)
                {
                    bool addressHasUsers = new UserService().CheckAddressHasUsersRegistered(
                        unitNumber: model.UnitNumber,
                        streetNumber: model.StreetNumber,
                        streetName: model.StreetName,
                        streetType: model.StreetType,
                        suburb: model.Suburb,
                        postcode: null
                        );

                    //This address still does not have registered users
                    if (!addressHasUsers)
                    {
                        var id = Guid.NewGuid();

                        Boolean isFBUser = false;
                        Boolean isApproved = false;
                        Int64 FBUserId = 0;

                        FacebookUserModel fbUser = null;
                        if (Session["FacebookUser"] != null)
                        {
                            fbUser = (FacebookUserModel)Session["FacebookUser"];
                        }

                        if (fbUser != null)
                        {
                            isFBUser = true;
                            isApproved = true;
                            FBUserId = Convert.ToInt64(fbUser.id);
                        }

                        // create the ASP membership user
                        MembershipCreateStatus status;

                        //Don't allow duplicate user
                        var tryToFindUser = Membership.GetUserNameByEmail(model.Email);
                        if (string.IsNullOrEmpty(tryToFindUser))
                        {
                            var membershipUser = Membership.CreateUser(username: model.Email, password: model.Password, email: model.Email,
                                passwordQuestion: null, passwordAnswer: null,
                                isApproved: isApproved, providerUserKey: id,
                                status: out status
                            );

                            if (status == MembershipCreateStatus.Success)
                            {
                                DateTime? saveDate = null;

                                if (model.DateOfBirthDay != null && model.DateOfBirthMonth != null && model.DateOfBirthYear != null)
                                {
                                    saveDate = new DateTime(year: (int)model.DateOfBirthYear.Value,
                                        month: (int)model.DateOfBirthMonth.Value,
                                        day: (int)model.DateOfBirthDay.Value);
                                }

                                // create the GM user
                                UserModel userModel = new UserModel();
                                userModel.Id = id;
                                userModel.FirstName = model.FirstName;
                                userModel.LastName = model.LastName;
                                userModel.AddressId = address.Id;
                                userModel.Instance_Id = address.Instance_Id;
                                userModel.SendEmailOffers = model.SendEmailOffers; //TODO check matching
                                userModel.SendEmailUpdates = model.SendEmailUpdates; //TODO check matching

                                userModel.IsFBAccount = isFBUser;
                                userModel.FBUserId = FBUserId;
                                userModel.IsAdditionalAccountHolder = false;
                                userModel.Sex = model.Sex;
                                userModel.DateOfBirth = saveDate;
                                userModel.PhoneNumber = model.PhoneNumber;

                                // Give them the New Member Bonus
                                int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.NewMember.Points"]);
                                string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.NewMember.Description"]);
                                int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                                UserModel newUserModel = new UserService().CreateUser(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                                if (newUserModel != null)
                                {
                                    FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false);
                                }

                                if (!isApproved)
                                {
                                    SendVerifyEmail(membershipUser.Email, userModel.FirstName, userModel.Id, true);
                                    // THey are a normal user
                                    //TODO later - email sending before approve, not it is approved immediately
                                    //SendVerifyEmail(membershipUser, user, true);
                                    membershipUser.IsApproved = true;
                                    Membership.UpdateUser(membershipUser);

                                    //TODO later - checkout what is this
                                    //if (false)
                                    //{
                                    //    // Add them to the relevant MailChimp List
                                    //    MailChimpManager mc = new MailChimpManager(ConfigurationManager.AppSettings["MailChimp.APIKey"]);
                                    //    EmailParameter email = new EmailParameter()
                                    //    {
                                    //        Email = user.Email
                                    //    };

                                    //    EmailParameter results = mc.Subscribe(ConfigurationManager.AppSettings["MailChimp.ListId"], email);
                                    //}

                                }
                                else
                                {
                                    // They have just logged in with FB so Login as usual
                                    FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false);
                                }

                                // the next registration step
                                return RedirectToAction("AddHouseholdMembers", new { addressId = address.Id, inviter = model.Email, inviterId = id });

                            }
                            else
                            {
                                ModelState.AddModelError("", ErrorCodeToString(status));
                            }
                        }
                        else
                        {
                            // email has already been registered in the system
                            ModelState.AddModelError("", "User with the same email address has already been registered with GreenMoney.");
                        }
                    }
                    else
                    {
                        // address already has a user on it!
                        ModelState.AddModelError("", "Address has already been registered with GreenMoney.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Please contact us with your address details and we'll assist you in creating an account.");

                    TempData["ProblemWithAddress"] = true;
                }
            }

            var suburbs = new UserService().GetAllSuburbs();
            var streetTypes = new UserService().GetAllStreetTypes();

            model.Suburbs = new SelectList(suburbs);
            model.StreetTypes = new SelectList(streetTypes);

            //Display
            LayoutViewModel.HideTopWrapperMenu = true;

            // something failed, redisplay form
            return View(model);
        }
예제 #4
0
        public AddressModel FindMatchingAdressModel(string unitNumber, string streetNumber, string streetName,
            string streetType, string suburb, string postcode = null)
        {
            var address = FindMatchingAdress(unitNumber, streetNumber, streetName, streetType, suburb, postcode);

            if (address != null)
            {
                AddressModel model = new AddressModel();
                Utils.CopyProperties(address, model);

                return model;
            }
            return null;
        }