예제 #1
0
        public UserModel AddUserToInInterestedPeople(UserModel userModel)
        {
            using (var context = new greenMoneyEntities())
            {
                var ip = new InterestedPeople
                {
                    FirstName = userModel.FirstName,
                    LastName = userModel.LastName,
                    SendEmailOffers = false,//registrationViewModel.SendEmailOffers, //Redesing
                    SendEmailUpdates = userModel.SendEmailOffers,
                    Email = userModel.Email,
                    Postcode = userModel.Postcode,
                    Gender = null, //model.Sex, //Redesing
                    DateOfBirth = userModel.DateOfBirth,
                    FreeStandingHome = true,
                    HasRfidTag = false,
                    StreetName = "N/A",
                    StreetNumber = "N/A",
                    StreetType = "N/A",
                    State = "N/A",
                    Suburb = "N/A",
                    UnitNumber = "N/A"
                };

                context.InterestedPeople.Add(ip);
                context.SaveChanges();

                return userModel;
            }
        }
예제 #2
0
        public ActionResult CompleteProfile(CompleteSupplierProfileViewModel viewModel)
        {
            LayoutViewModel.ActiveLink = Links.SupplierUpdateProfile;

            LayoutViewModel.HideTopWrapperMenu = true;

            var userModel = new UserModel
            {
                Id = LayoutViewModel.CurrentAccountId,
                BusinessNumberABN = viewModel.BusinessNumberABN,
                BusinessType = viewModel.BusinessType,
                BussinesWebSite = viewModel.BussinesWebSite
            };

            var updated = new UserService().UpdateToCompleteSupplierUser(userModel);

            return RedirectToAction("CreateReward");
        }
예제 #3
0
        public static void SendEmailResetPassword(string emailContentPath, UserModel user, string password, string url, MembershipUser membershipUser)
        {
            // email content
            var bodyContent = Razor.Parse(
                System.IO.File.ReadAllText(emailContentPath),
                new
                {
                    FirstName = user.FirstName,
                    Password = password,
                    LoginUrl = url
                }
                );

            var recipientEmail = SetRecipientEmail(membershipUser.Email);

            try
            {

                // create email request
                var request = new SendEmailRequest()
                    .WithDestination(new Destination(new List<string> {recipientEmail}))
                    .WithSource("*****@*****.**")
                    .WithReturnPath("*****@*****.**")
                    .WithMessage(new Message()
                        .WithSubject(new Content("GreenMoney Password Reset"))
                        .WithBody(new Body().WithHtml(new Content(bodyContent)))
                    );

                // send it
                var client = new AmazonSimpleEmailServiceClient("AKIAIDP5FFSCJUHHC4QA", "NKAzwbtwwhvKuQZj2t6OXxOhaOEuaBYh3E34Jxbs");
                client.SendEmail(request);

            }
            catch (Exception)
            {

            }
        }
예제 #4
0
        public ActionResult Index(UpdateSupplierProfileViewModel viewModel)
        {
            LayoutViewModel.ActiveLink = Links.SupplierUpdateProfile;

            var membershipUser = Membership.GetUser();

            if (ModelState.IsValid)
            {
                UserModel userModel = new UserModel
                {
                    Id = LayoutViewModel.CurrentAccountId,
                    FirstName = viewModel.FirstName,
                    LastName = viewModel.LastName,
                    PhotoID = viewModel.PhotoID,
                    BusinessName = viewModel.BusinessName,
                    BusinessNumberABN = viewModel.BusinessNumberABN,
                    BusinessType = viewModel.BusinessType,
                    BussinesEmail = viewModel.BussinesEmail,
                    BussinesLocation = viewModel.BussinesLocation,
                    BussinesPhone = viewModel.BussinesPhone,
                    BussinesPhoneArea = viewModel.BussinesPhoneArea,
                    BussinesPhoneMobile = viewModel.BussinesPhoneMobile,
                    BussinesWebSite = viewModel.BussinesWebSite,
                    EmailBussinesOnVoucherRedeem = viewModel.EmailBussinesOnVoucherRedeem,
                    SendEmailUpdates = viewModel.SendEmailUpdates
                };

                var success = true;

                // change password
                if (!string.IsNullOrEmpty(viewModel.OldPassword) || !string.IsNullOrEmpty(viewModel.NewPassword)
                    || !string.IsNullOrEmpty(viewModel.ConfirmNewPassword))
                {
                    if (string.IsNullOrEmpty(viewModel.OldPassword))
                    {
                        ModelState.AddModelError("OldPassword", "The Old password field is required.");
                        success = false;
                    }

                    if (string.IsNullOrEmpty(viewModel.NewPassword))
                    {
                        ModelState.AddModelError("NewPassword", "The New password field is required.");
                        success = false;
                    }

                    if (string.IsNullOrEmpty(viewModel.ConfirmNewPassword))
                    {
                        ModelState.AddModelError("ConfirmNewPassword", "The Confirm new password field is required.");
                        success = false;
                    }

                    if (success && viewModel.NewPassword != viewModel.ConfirmNewPassword)
                    {
                        ModelState.AddModelError("ConfirmNewPassword", "New password and confirmation password do not match.");
                        success = false;
                    }

                    if (success && !membershipUser.ChangePassword(viewModel.OldPassword, viewModel.NewPassword))
                    {
                        ModelState.AddModelError("OldPassword", "Old password is incorrect.");
                        success = false;
                    }
                }

                if (viewModel.Photo != null && viewModel.Photo.ContentLength > 0)
                {
                    MemoryStream target = new MemoryStream();
                    viewModel.Photo.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();

                    UploadModel model = new UploadModel
                    {
                        ContentType = viewModel.Photo.ContentType,
                        Contents = data,
                        FileName = viewModel.Photo.FileName
                    };

                    UploadModel upload = new UploadService().UploadFile(membershipUser.ProviderUserKey.ToString(), model, true);

                }

                if (success)
                {
                    var updated = new UserService().UpdateSupplierUser(userModel);

                    // change username COMPLICATED
                    if (membershipUser.UserName != viewModel.BussinesEmail)
                    {

                        var config = WebConfigurationManager.OpenWebConfiguration("~");
                        var section = config.SectionGroups["system.web"].Sections["membership"] as MembershipSection;
                        var defaultProvider = section.DefaultProvider;
                        var connectionStringName = section.Providers[defaultProvider].ElementInformation.Properties["connectionStringName"].Value.ToString();

                        string connectionString = config.ConnectionStrings.ConnectionStrings[connectionStringName].ConnectionString;

                        var changed = new ProfileService().ChangeUsername(membershipUser.UserName, viewModel.BussinesEmail, connectionString);

                        if (changed)
                        {
                            // change email as well
                            membershipUser.Email = viewModel.BussinesEmail;

                            // need to re-verify
                            membershipUser.IsApproved = false;
                            //SendVerifyEmail(membershipUser, user, false);
                            //instead I'm showing verifucation code in the view

                            Membership.UpdateUser(membershipUser);

                            // need to sign out to force verification
                            FormsAuthentication.SignOut();

                            TempData["VerifyCode"] = ZBase32.Encode(LayoutViewModel.CurrentAccountId.ToByteArray());

                            // redirect to screen which tells user to check email
                            return RedirectToAction("EmailChangeSuccess", "Account");
                        }
                        else
                        {
                            ModelState.AddModelError("", "A user for that email address already exists. Please enter a different email address.");
                        }
                    }

                    return RedirectToAction("Dashboard");
                }

                return View(viewModel);
            }

            return View(viewModel);
        }
예제 #5
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);
        }
예제 #6
0
        public ActionResult RegisterHouseholdMembers(HouseholdMemberModel householdMemberModel)
        {
            AddressModel address = new UserService().GetAddressById(householdMemberModel.AddressId);

            //Don't allow duplicate user
            var tryToFindUser = Membership.GetUserNameByEmail(householdMemberModel.Email);
            if (string.IsNullOrEmpty(tryToFindUser))
            {

                var id = Guid.NewGuid();

                Boolean isFBUser = false;
                Boolean isApproved = true;
                Int32 FBUserId = 0;

                // create the ASP membership user
                MembershipCreateStatus status;
                var membershipUser = Membership.CreateUser(username: householdMemberModel.Email, password: householdMemberModel.Password, email: householdMemberModel.Email,
                    passwordQuestion: null, passwordAnswer: null,
                    isApproved: isApproved, providerUserKey: id,
                    status: out status
                );

                // Check inviter user role and the same role for invited user
                var addressHolderUserEmail = new UserService().GetUserNameHolderForAddress(householdMemberModel.AddressId);
                if (!string.IsNullOrWhiteSpace(addressHolderUserEmail))
                {
                    if (Roles.IsUserInRole(addressHolderUserEmail, "Supplier") && membershipUser != null)
                    {
                        Roles.AddUserToRole(membershipUser.Email, "Supplier");
                    }
                }

                if (status == MembershipCreateStatus.Success)
                {
                    // create the GM user
                    var user = new UserModel
                    {
                        Id = id,
                        FirstName = householdMemberModel.FirstName,
                        LastName = householdMemberModel.LastName,
                        AddressModel = address,
                        AddressId = address.Id,
                        Instance_Id = address.Instance_Id,
                        SendEmailOffers = householdMemberModel.SendEmailOffers,
                        SendEmailUpdates = householdMemberModel.SendEmailUpdates,
                        IsFBAccount = isFBUser,
                        FBUserId = FBUserId,
                        IsAdditionalAccountHolder = true
                    };

                    // 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"]);

                    // store it
                    var newUser = new UserService().CreateUser(user, numBonusPoints, descBonusPoints, transactionTypeId);

                    int numBonusInvitationAcceptedPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Points"]);
                    string descInvitationAcceptedBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Description"]);

                    bool addPoints = new UserService().InvitationAcceptedAddBonusPoints(addressHolderUserEmail,
                        numBonusInvitationAcceptedPoints, descInvitationAcceptedBonusPoints, transactionTypeId);

                    SendVerifyEmail(membershipUser.Email, user.FirstName, user.Id, true);

                    bool isProduction = Convert.ToBoolean(ConfigurationManager.AppSettings["MailChimp.ListId"]);

                    if (isProduction)
                    {
                        // 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);

                    }

                    return RedirectToAction("RegisterAccountSuccess");

                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(status));
                    return View(householdMemberModel);
                }
            }
            else
            {
                // email has already been registered in the system
                ModelState.AddModelError("", "User with the same email address has already been registered with GreenMoney.");
                return View(householdMemberModel);

            }
        }
예제 #7
0
        public UserModel UpdateSupplierUser(UserModel model)
        {
            using (var context = new greenMoneyEntities())
            {
                var user = context.Users1.Find(model.Id);

                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.SendEmailOffers = model.SendEmailOffers;
                user.SendEmailUpdates = model.SendEmailUpdates;
                user.IsFBAccount = model.IsFBAccount;
                user.BusinessName = model.BusinessName;
                user.BusinessNumberABN = model.BusinessNumberABN;
                user.BusinessType = model.BusinessType;
                user.BussinesWebSite = model.BussinesWebSite;
                user.BussinesEmail = model.BussinesEmail;
                user.BussinesPhone = model.BussinesPhone;
                user.BussinesPhoneArea = model.BussinesPhoneArea;
                user.BussinesPhoneMobile = model.BussinesPhoneMobile;
                user.BussinesLocation = model.BussinesLocation;
                user.EmailBussinesOnVoucherRedeem = model.EmailBussinesOnVoucherRedeem;

                context.SaveChanges();

                return GetUserById(user.Id);
            }
        }
예제 #8
0
        public bool UpdateToCompleteSupplierUser(UserModel model)
        {
            using (var context = new greenMoneyEntities())
            {
                var user = context.Users1.Find(model.Id);

                user.BusinessNumberABN = model.BusinessNumberABN;
                user.BusinessType = model.BusinessType;
                user.BussinesWebSite = model.BussinesWebSite;

                context.SaveChanges();

                return true;
            }
        }
예제 #9
0
        public List<UserModel> GetInvitedUsersAccounts(string inviterId)
        {
            using (var context = new greenMoneyEntities())
            {
                var invitedAccounts = context.InvitedUsers.Where(x => x.User_Id == new Guid(inviterId)).ToList();

                var users = new List<UserModel>();
                foreach (var item in invitedAccounts)
                {
                    var m = new UserModel
                    {
                        FirstName = item.FirstName,
                        LastName = item.LastName,
                        Email = item.Email
                    };

                    users.Add(m);
                }

                return users;
            }
        }
예제 #10
0
        public UserModel GetUserById(Guid id)
        {
            using (var context = new greenMoneyEntities())
            {
                var user = context.Users1.FirstOrDefault(i => i.Id == id);

                if (user == null)
                {
                    return null;
                }

                var model = new UserModel
                {
                    AddressModel = new AddressModel()
                };

                Utils.CopyProperties(user, model);
                Utils.CopyProperties(user.Addresses, model.AddressModel);

                return model;
            }
        }
예제 #11
0
 public bool UpdateToCompleteSupplierUser(UserModel model)
 {
     return new UserRepository().UpdateToCompleteSupplierUser(model);
 }
예제 #12
0
 public UserModel UpdateSupplierUser(UserModel model)
 {
     return new UserRepository().UpdateSupplierUser(model);
 }
예제 #13
0
        public List<UserModel> GetAdditionalAccounts(string p)
        {
            using (var context = new greenMoneyEntities())
            {
                var user = context.Users1.FirstOrDefault(x => x.Id == new Guid(p));
                var additionalAccountHolders =
                   context.Users1.Where(x => x.Addresses.Id == user.Addresses.Id && x.IsAdditionalAccountHolder == true)
                        .ToList();

                List<UserModel> users = new List<UserModel>();
                foreach (var item in additionalAccountHolders)
                {
                    UserModel m = new UserModel();
                    Utils.CopyProperties(item, m);

                    m.Email = item.Users.UserName;
                    users.Add(m);
                }

                return users;

                //What is this??
                //model.IsAdditionalThemselves = user.IsAdditionalAccountHolder;
            }
        }
예제 #14
0
        public UserModel CreateUser(UserModel model, int numPoints, string description, int? transactionTypeId)
        {
            using (var context = new greenMoneyEntities())
            {
                var address = context.Addresses.First(i => i.Id == model.AddressId);
                var user = new Users1
                {
                    Id = model.Id,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Addresses = address,
                    SendEmailOffers = model.SendEmailOffers,
                    SendEmailUpdates = model.SendEmailUpdates,
                    IsFBAccount = model.IsFBAccount,
                    FBUserId = model.FBUserId,
                    IsAdditionalAccountHolder = model.IsAdditionalAccountHolder,
                    Sex = model.Sex,
                    DateOfBirth = model.DateOfBirth,
                    PhoneNumber = model.PhoneNumber
                };

                if (address.Instance_Id != null)
                    user.Instance_Id = (int)address.Instance_Id;

                // store it
                context.Users1.Add(user);

                AddPoints(context, user, numPoints, description, transactionTypeId);

                context.SaveChanges();

                return GetUserById(user.Id);
            }
        }
예제 #15
0
        public UserModel CreateSupplierUser(UserModel model, int numPoints, string description, int? transactionTypeId)
        {
            using (var context = new greenMoneyEntities())
            {
                var address = context.Addresses.First(i => i.Id == model.AddressId);
                var user = new Users1
                {
                    Id = model.Id,
                    Instance_Id = model.Instance_Id,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Addresses = address,
                    SendEmailUpdates = model.SendEmailUpdates,
                    IsAdditionalAccountHolder = model.IsAdditionalAccountHolder,
                    BusinessName = model.BusinessName,
                    BusinessNumberABN = model.BusinessNumberABN,
                    BusinessType = model.BusinessType,
                    BussinesWebSite = model.BussinesWebSite,
                    BussinesEmail = model.BussinesEmail,
                    BussinesPhone = model.BussinesPhone,
                    BussinesPhoneArea = model.BussinesPhoneArea,
                    BussinesPhoneMobile = model.BussinesPhoneMobile,
                    BussinesLocation = model.BussinesLocation,
                    EmailBussinesOnVoucherRedeem = model.EmailBussinesOnVoucherRedeem
                };

                // store it
                context.Users1.Add(user);

                AddPoints(context, user, numPoints, description, transactionTypeId);

                context.SaveChanges();

                return GetUserById(user.Id);
            }
        }
예제 #16
0
 public UserModel CreateUser(UserModel model, int numPoints, string description, int? transactionTypeId)
 {
     return new UserRepository().CreateUser(model, numPoints, description, transactionTypeId);
 }
예제 #17
0
 public UserModel AddUserToInInterestedPeople(UserModel userModel)
 {
     return new UserRepository().AddUserToInInterestedPeople(userModel);
 }
예제 #18
0
        public ActionResult RegisterSupplier(RegistrationSupplierViewModel registrationSupplierViewModel)
        {
            if (ModelState.IsValid)
            {

                //Don't allow duplicate user
                var tryToFindUser = Membership.GetUserNameByEmail(registrationSupplierViewModel.BusinessEmail);
                if (string.IsNullOrEmpty(tryToFindUser))
                {

                    // Create the ASP membership user
                    var id = Guid.NewGuid();
                    MembershipCreateStatus status;

                    var membershipUser = Membership.CreateUser(username: registrationSupplierViewModel.BusinessEmail,
                        password: registrationSupplierViewModel.Password, email: registrationSupplierViewModel.BusinessEmail,
                        passwordQuestion: null, passwordAnswer: null,
                        isApproved: true, providerUserKey: id,
                        status: out status
                    );

                    if (status == MembershipCreateStatus.Success)
                    {

                        // Create the GM user for supplier with default address (temp id= 258440)
                        UserModel userModel = new UserModel();
                        userModel.Id = id;
                        userModel.Instance_Id = registrationSupplierViewModel.InstanceId;
                        userModel.BusinessName = registrationSupplierViewModel.BusinessName;

                        // TODO - think about logic Email vs. BusinessEmail
                        userModel.BussinesEmail = registrationSupplierViewModel.BusinessEmail;
                        userModel.Email = registrationSupplierViewModel.BusinessEmail;

                        userModel.BussinesPhoneArea = registrationSupplierViewModel.BussinesPhoneArea;
                        userModel.BussinesPhone = registrationSupplierViewModel.BusinessPhone;
                        userModel.FirstName = registrationSupplierViewModel.FirstName;
                        userModel.LastName = registrationSupplierViewModel.LastName;

                        userModel.AddressId = int.Parse(ConfigurationManager.AppSettings["DefaultSupplierAddressId"]);
                        //TODO this should be bigint actually? add error logging
                        userModel.IsAdditionalAccountHolder = false;

                        // 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().CreateSupplierUser(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                        if (newUserModel != null)
                        {
                            if (!Roles.IsUserInRole(membershipUser.Email, "Supplier"))
                            {
                                Roles.AddUserToRole(membershipUser.Email, "Supplier");
                            }
                            FormsAuthentication.SetAuthCookie(registrationSupplierViewModel.BusinessEmail, createPersistentCookie: false);
                        }
                    }

                    return RedirectToAction("CompleteProfile", "Supplier");
                }
                else
                {
                    return RedirectToAction("Index", "Business");
                }
            }
            else // something failed, redisplay form
            {
                BusinessHomeViewModel viewModel = new BusinessHomeViewModel();
                viewModel.SupplierRegistrationIsNotValid = true;

                var instances = new UserService().GetAllInstances();
                registrationSupplierViewModel.Instances = new SelectList(instances, "Id", "Name");
                viewModel.RegistrationSupplierViewModel = registrationSupplierViewModel;

                LayoutViewModel.IsAuthenticated = false;
                LayoutViewModel.HideTopWrapperMenu = true;

                return View("Index", viewModel);
            }
        }
예제 #19
0
        public UserModel GetFacebookUser(long userId)
        {
            using (var context = new greenMoneyEntities())
            {
                var user = context.Users1.SingleOrDefault(a => a.IsFBAccount && a.FBUserId == userId);

                if (user == null)
                {
                    return null;
                }

                UserModel model = new UserModel();
                Utils.CopyProperties(user, model);

                model.Email = user.Users.UserName;

                return model;
            }
        }