Example #1
0
        public ActionResult UpdateEmptyLatLong(int[] companyId)
        {
            GeoLocator locator = new GeoLocator();
            CompanyProfile company;

            try
            {
                for (int i = 0; i < companyId.Length; i++)
                {
                    company = _service.Get(companyId[i]);
                    if (company.Id != 1)
                    {
                        if (company.Address1 == null && company.City == null && company.StateId != null && company.PostalCode != null)
                        {
                            company.GeoLocation = locator.GetFromStateZip(company.State.Abbr, company.PostalCode);
                            _service.Update(company);
                        }
                        else if ((company.Address1 == null || company.Address1 == string.Empty) && company.StateId != null && company.PostalCode != null)
                        {
                            company.GeoLocation = locator.GetFromCityStateZip(company.City, company.State.Abbr, company.PostalCode);
                            _service.Update(company);
                        }
                        else if ((company.Address1 != null && company.Address1 != string.Empty) && (company.City != null && company.City != string.Empty) && company.StateId != null && company.PostalCode != null)
                        {
                            company.GeoLocation = locator.GetFromAddress(company.Address1, company.City, company.State.Abbr, company.PostalCode);
                            _service.Update(company);
                        }
                    }
                }
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {

                throw new HttpException(500, ex.Message);
            }
        }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(string city, string state, string postal, double distance)
        {
            // call up the locator
            GeoLocator locator = new GeoLocator();

            // get a search point
            DbGeography searchPoint = locator.GetFromAddress("", city, state, postal);

            var results = from c in _repo.Query()
                          where (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= distance
                          select c;

            return results.AsEnumerable();
        }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(int projectEntityId, ProjectEntityType type)
        {
            IEnumerable<CompanyProfile> result;
            GeoLocator locator = new GeoLocator(); // call up the locator
            BidPackage theBp;
            DbGeography searchPoint;
            int projectIdforLocation = 0;

            switch (type)
            {
                case ProjectEntityType.bidPackage:

                    theBp = _repo.FindBidPackage(projectEntityId);
                    projectIdforLocation = theBp.ProjectId;

                    searchPoint = _repo.FindProject(projectIdforLocation).GeoLocation;

                    int[] bpScopes = theBp.Scopes.Where(s => s.Scope.Children == null).Select(s => s.ScopeId).ToArray();

                    result = from c in _repo.Query()
                             where c.Scopes.Any(s => bpScopes.Contains(s.ScopeId))
                             && (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= c.OperatingDistance
                             select c;

                    return result.ToList();

                case ProjectEntityType.project:

                    projectIdforLocation = projectEntityId;

                    searchPoint = _repo.FindProject(projectIdforLocation).GeoLocation;

                    result = from c in _repo.Query()
                             where (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= c.OperatingDistance
                             select c;

                    return result.ToList();

                default:
                    throw new Exception("unknown entity type");
            }
        }
Example #4
0
        public ActionResult CreateStepTwo(ProjectEditModel viewModel)
        {
            if (!viewModel.ProjectCategory.HasValue)
                ModelState.AddModelError("ProjectCategory", "Project Category is required");
            if (!viewModel.ProjectType.HasValue)
                ModelState.AddModelError("ProjectType", "Project Type is required");

            if (ModelState.IsValid)
            {
                try
                {

                    int userId = _security.GetUserId(User.Identity.Name);
                    int companyId = _service.GetUserProfile(userId).CompanyId;

                    // create project
                    BCModel.Projects.Project toCreate = new BCModel.Projects.Project
                    {
                        Number = viewModel.Number,
                        ArchitectId = viewModel.ArchitectId,
                        Address = viewModel.Address,
                        BidDateTime = viewModel.BidDateTime,
                        BuildingTypeId = viewModel.BuildingTypeId,
                        City = viewModel.City,
                        ConstructionTypeId = viewModel.ConstructionTypeId,
                        CreatedById = userId,
                        Description = viewModel.Description,
                        PostalCode = viewModel.PostalCode,
                        ProjectType = viewModel.ProjectType.Value,
                        ProjectCategory = viewModel.ProjectCategory.Value,
                        StateId = viewModel.StateId,
                        Title = viewModel.Title,
                        Scopes = new List<ProjectXScope>(),
                        BidPackages = new List<BidPackage>(),
                        WalkThruDateTime = viewModel.WalkThruDateTime,
                        WalkThruStatus = viewModel.WalkThruStatus.Value,
                        HiddenFromSearch = viewModel.HiddenFromSearch,
                        InvitationOnly = viewModel.InvitationOnly
                    };

                    GeoLocator locator = new GeoLocator();

                    string state = _service.GetStates().Where(x => x.Id == viewModel.StateId).FirstOrDefault().Abbr;

                    if (viewModel.Address == null || viewModel.Address == string.Empty)
                    {
                        toCreate.GeoLocation = locator.GetFromCityStateZip(viewModel.City, state, viewModel.PostalCode);
                    }
                    else
                    {
                        toCreate.GeoLocation = locator.GetFromAddress(viewModel.Address, viewModel.City, state, viewModel.PostalCode);
                    }

                    // create master bid package
                    BidPackage projectPackage = new BidPackage
                    {
                        IsMaster = true,
                        BidDateTime = toCreate.BidDateTime,
                        Description = "Master Bid Package",
                        CreatedById = viewModel.ArchitectId,
                        Project = toCreate,
                        Scopes = new List<BidPackageXScope>(),
                        Invitees = new List<Invitation>()
                    };

                    // if user is a GC, self-invite
                    if (_security.IsUserInRole("general_contractor"))
                    {
                        projectPackage.Invitees.Add(new Invitation
                        {
                            BidPackage = projectPackage,
                            SentToId = companyId,
                            SentDate = DateTime.Now,
                            AcceptedDate = DateTime.Now,
                            InvitationType = InvitationType.SentFromCreatedBy
                        });
                    }

                    // add bp to project
                    toCreate.BidPackages.Add(projectPackage);

                    // set selected scopes for bp and project
                    for (int i = 0; i < viewModel.SelectedScope.Count(); i++)
                    {
                        toCreate.Scopes.Add(new ProjectXScope { Project = toCreate, ScopeId = viewModel.SelectedScope.ElementAt(i) });
                        projectPackage.Scopes.Add(new BidPackageXScope { BidPackage = projectPackage, ScopeId = viewModel.SelectedScope.ElementAt(i) });
                    }

                    // add project to system
                    if (_service.Create(toCreate))
                    {
                        return RedirectToRoute("Default", new { controller = "Project", action = "Details", id = toCreate.Id });
                    }
                    else
                    {
                        Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                        rePopViewModel(viewModel);
                        return View("CreateStepTwo", viewModel);
                    }
                }
                catch (Exception ex)
                {

                    ModelState.AddModelError("Exception", ex.Message);
                    rePopViewModel(viewModel);
                    return View("CreateStepTwo", viewModel);
                }
            }

            // modelstate is not valid
            rePopViewModel(viewModel);
            return View("CreateStepTwo", viewModel);
        }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(BCModel.BusinessType[] types, string city, string state, string postal, double distance, int[] scopes)
        {
            // call up the locator
            GeoLocator locator = new GeoLocator();

            // get a search point
            DbGeography searchPoint = locator.GetFromAddress("", city, state, postal);

            var results = from c in _repo.Query()
                          where types.Contains(c.BusinessType)
                          && c.Scopes.Any(s => scopes.Contains(s.ScopeId))
                          && (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= distance
                          select c;

            return results.AsEnumerable();
        }
Example #6
0
        public ActionResult Edit(EditCompanyViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                // get company
                int userId = _security.GetUserId(User.Identity.Name);
                var company = _serviceLayer.GetUserProfiles(u => u.UserId == userId).FirstOrDefault().Company;

                if (viewModel.Address1 != null)
                    company.Address1 = viewModel.Address1.Trim();
                if (viewModel.Address2 != null)
                    company.Address2 = viewModel.Address2.Trim();

                company.City = viewModel.City;
                company.CompanyName = viewModel.CompanyName.Trim();
                company.OperatingDistance = viewModel.OperatingDistance;
                company.Phone = Util.ConvertPhoneForStorage(viewModel.Phone.Trim());
                company.PostalCode = viewModel.PostalCode.Trim();
                //company.StateId = viewModel.StateId;
                company.State = _serviceLayer.GetState(viewModel.StateId.Value);
                GeoLocator locator = new GeoLocator();

                if (company.Address1 == null && company.City == null && company.StateId != null && company.PostalCode != null)
                {

                    company.GeoLocation = locator.GetFromStateZip(company.State.Abbr, company.PostalCode);
                }
                else if ((company.Address1 == null || company.Address1 == string.Empty) && company.StateId != null && company.PostalCode != null)
                {
                    company.GeoLocation = locator.GetFromCityStateZip(company.City, company.State.Abbr, company.PostalCode);
                }
                else if ((company.Address1 != null && company.Address1 != string.Empty) && (company.City != null && company.City != string.Empty) && company.StateId != null && company.PostalCode != null)
                {
                    company.GeoLocation = locator.GetFromAddress(company.Address1, company.City, company.State.Abbr, company.PostalCode);
                }

                // did business type change?
                if (company.BusinessType != viewModel.BusinessType)
                {

                    // add new role for all users in company
                    switch (viewModel.BusinessType.Value)
                    {
                        case BusinessType.GeneralContractor:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "general_contractor");
                            break;
                        case BusinessType.SubContractor:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "subcontractor");
                            break;
                        case BusinessType.Architect:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "architect");
                            break;
                        case BusinessType.Engineer:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "engineer");
                            break;
                        case BusinessType.Owner:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "owner_client");
                            break;
                        case BusinessType.MaterialsVendor:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "materials_vendor");
                            break;
                        case BusinessType.MaterialsMfg:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "materials_manufacturer");
                            break;
                        case BusinessType.Consultant:
                            _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "consultant");
                            break;
                    };

                    // remove old role for all users in company
                    switch (company.BusinessType)
                    {
                        case BusinessType.GeneralContractor:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "general_contractor");
                            break;
                        case BusinessType.SubContractor:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "subcontractor");
                            break;
                        case BusinessType.Architect:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "architect");
                            break;
                        case BusinessType.Engineer:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "engineer");
                            break;
                        case BusinessType.Owner:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "owner_client");
                            break;
                        case BusinessType.MaterialsVendor:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "materials_vendor");
                            break;
                        case BusinessType.MaterialsMfg:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "materials_manufacturer");
                            break;
                        case BusinessType.Consultant:
                            _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "consultant");
                            break;
                    };

                    // update company business type
                    company.BusinessType = viewModel.BusinessType.Value;
                }

                // update changes in the database
                if (_serviceLayer.Update(company))
                {
                    return RedirectToRoute("Default", new { controller = "Account", action = "Manage", message = ManageMessageId.ChangeCompanyInfoSuccess });
                }
                else
                {
                    Util.MapValidationErrors(_serviceLayer.ValidationDic, this.ModelState);
                    viewModel.States = _serviceLayer.GetStates().Select(x => new SelectListItem { Text = x.Abbr, Value = x.Id.ToString(), Selected = x.Id == viewModel.StateId });
                    //viewModel.BusinessTypes = _serviceLayer.GetBusinessTypes().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == viewModel.BusinessTypeId });
                    return View(viewModel);
                }
            }
            else
            {
                viewModel.States = _serviceLayer.GetStates().Select(x => new SelectListItem { Text = x.Abbr, Value = x.Id.ToString(), Selected = x.Id == viewModel.StateId });
                //viewModel.BusinessTypes = _serviceLayer.GetBusinessTypes().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == viewModel.BusinessTypeId });
                return View(viewModel);
            }
        }
Example #7
0
        public ActionResult Create(BCWeb.Areas.Admin.Models.Projects.ViewModel.ProjectEditModel viewModel)
        {
            if (!viewModel.ProjectCategory.HasValue)
                ModelState.AddModelError("ProjectCategory", "Project Category is required");
            if (!viewModel.ProjectType.HasValue)
                ModelState.AddModelError("ProjectType", "Project Type is required");

            if (ModelState.IsValid)
            {
                BCModel.Projects.Project toCreate = new BCModel.Projects.Project
                {
                    Address = viewModel.Address,
                    ArchitectId = viewModel.ArchitectId,
                    BidDateTime = viewModel.BidDateTime,
                    BuildingTypeId = viewModel.BuildingTypeId,
                    City = viewModel.City,
                    ConstructionTypeId = viewModel.ConstructionTypeId,
                    CreatedById = viewModel.CreatedById,
                    Description = viewModel.Description,
                    Number = viewModel.Number,
                    PostalCode = viewModel.PostalCode,
                    ProjectCategory = viewModel.ProjectCategory.Value,
                    ProjectType = viewModel.ProjectType.Value,
                    StateId = viewModel.StateId,
                    Title = viewModel.Title,
                    BidPackages = new List<BidPackage>(),
                    Scopes = new List<ProjectXScope>(),
                    WalkThruDateTime = viewModel.WalkThruDateTime,
                    WalkThruStatus = viewModel.WalkThruStatus.Value
                };

                GeoLocator locator = new GeoLocator();
                State projectState = _service.GetState(viewModel.StateId);

                if (viewModel.Address == null && viewModel.City == null && viewModel.StateId != null && viewModel.PostalCode != null)
                {
                    toCreate.GeoLocation = locator.GetFromStateZip(projectState.Abbr, viewModel.PostalCode);
                }
                else if ((viewModel.Address == null || viewModel.Address == string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null)
                {
                    toCreate.GeoLocation = locator.GetFromCityStateZip(viewModel.City, projectState.Abbr, viewModel.PostalCode);
                }
                else if ((viewModel.Address != null && viewModel.Address != string.Empty) && (viewModel.City != null && viewModel.City != string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null)
                {
                    toCreate.GeoLocation = locator.GetFromAddress(viewModel.Address, viewModel.City, projectState.Abbr, viewModel.PostalCode);
                }

                BidPackage projectPackage = new BidPackage
                {
                    IsMaster = true,
                    BidDateTime = toCreate.BidDateTime,
                    Description = "Master Bid Package",
                    CreatedById = viewModel.ArchitectId,
                    Project = toCreate,
                    Scopes = new List<BidPackageXScope>(),
                    Invitees = new List<Invitation>()
                };

                UserProfile createdBy = _service.GetUserProfile(viewModel.CreatedById);

                // if createdby is a GC, self-invite
                if (createdBy.Company.BusinessType == BusinessType.GeneralContractor)
                {
                    projectPackage.Invitees.Add(new Invitation
                    {
                        BidPackage = projectPackage,
                        SentToId = viewModel.CreatedById,
                        SentDate = DateTime.Now,
                        AcceptedDate = DateTime.Now,
                        InvitationType = InvitationType.SentFromCreatedBy
                    });
                }

                // add bp to project
                toCreate.BidPackages.Add(projectPackage);

                // set selected scopes for bp and project
                for (int i = 0; i < viewModel.SelectedScope.Count(); i++)
                {
                    toCreate.Scopes.Add(new ProjectXScope { Project = toCreate, ScopeId = viewModel.SelectedScope.ElementAt(i) });
                    projectPackage.Scopes.Add(new BidPackageXScope { BidPackage = projectPackage, ScopeId = viewModel.SelectedScope.ElementAt(i) });
                }

                // add project to system
                if (_service.Create(toCreate))
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                }

            }
            rePopVieModel(viewModel);
            return View();
        }
Example #8
0
        public ActionResult UpdateEmptyLatLong(int[] projectId)
        {
            GeoLocator locator = new GeoLocator();
            BCModel.Projects.Project theProject;
            for (int i = 0; i < projectId.Length; i++)
            {

                theProject = _service.Get(projectId[i]);

                if (theProject.Address == null && theProject.City == null && theProject.StateId != null && theProject.PostalCode != null)
                {
                    theProject.GeoLocation = locator.GetFromStateZip(theProject.State.Abbr, theProject.PostalCode);
                    _service.Update(theProject);
                }
                else if ((theProject.Address == null || theProject.Address == string.Empty) && theProject.StateId != null && theProject.PostalCode != null)
                {
                    theProject.GeoLocation = locator.GetFromCityStateZip(theProject.City, theProject.State.Abbr, theProject.PostalCode);
                    _service.Update(theProject);
                }
                else if ((theProject.Address != null && theProject.Address != string.Empty) && (theProject.City != null && theProject.City != string.Empty) && theProject.StateId != null && theProject.PostalCode != null)
                {
                    theProject.GeoLocation = locator.GetFromAddress(theProject.Address, theProject.City, theProject.State.Abbr, theProject.PostalCode);
                    _service.Update(theProject);
                }
            }

            return RedirectToAction("Index");
        }
Example #9
0
        public ActionResult Edit(BCWeb.Areas.Admin.Models.Projects.ViewModel.ProjectEditModel viewModel)
        {
            BCModel.Projects.Project toUpdate = _service.Get(viewModel.Id);
            toUpdate.Address = viewModel.Address;
            toUpdate.ArchitectId = viewModel.ArchitectId;
            toUpdate.BidDateTime = viewModel.BidDateTime;
            toUpdate.BuildingTypeId = viewModel.BuildingTypeId;
            toUpdate.City = viewModel.City;
            toUpdate.ConstructionTypeId = viewModel.ConstructionTypeId;
            toUpdate.CreatedById = viewModel.CreatedById;
            toUpdate.Description = viewModel.Description;
            toUpdate.Number = viewModel.Number;
            toUpdate.PostalCode = viewModel.PostalCode;
            toUpdate.ProjectCategory = viewModel.ProjectCategory.Value;
            toUpdate.ProjectType = viewModel.ProjectType.Value;
            toUpdate.StateId = viewModel.StateId;
            toUpdate.Title = viewModel.Title;
            toUpdate.BidPackages = new List<BidPackage>();
            toUpdate.Scopes = new List<ProjectXScope>();
            toUpdate.WalkThruDateTime = viewModel.WalkThruDateTime;
            toUpdate.WalkThruStatus = viewModel.WalkThruStatus.Value;

            GeoLocator locator = new GeoLocator();
            State projectState = _service.GetState(viewModel.StateId);

            if (viewModel.Address == null && viewModel.City == null && viewModel.StateId != null && viewModel.PostalCode != null)
            {
                toUpdate.GeoLocation = locator.GetFromStateZip(projectState.Abbr, viewModel.PostalCode);
            }
            else if ((viewModel.Address == null || viewModel.Address == string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null)
            {
                toUpdate.GeoLocation = locator.GetFromCityStateZip(viewModel.City, projectState.Abbr, viewModel.PostalCode);
            }
            else if ((viewModel.Address != null && viewModel.Address != string.Empty) && (viewModel.City != null && viewModel.City != string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null)
            {
                toUpdate.GeoLocation = locator.GetFromAddress(viewModel.Address, viewModel.City, projectState.Abbr, viewModel.PostalCode);
            }

            try
            {
                if (_service.Update(toUpdate))
                {
                    return RedirectToAction("Details", new { id = toUpdate.Id });
                }
                else
                {
                    Util.MapValidationErrors(_service.ValidationDic, ModelState);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Exception", ex.Message);
            }
            rePopVieModel(viewModel);
            return View(viewModel);
        }
Example #10
0
        public ActionResult Register(RegisterModel model)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();
            model.States = _serviceLayer.GetStates().Select(x => new SelectListItem { Text = x.Abbr, Value = x.Id.ToString() });
            //model.BusinessTypes = _serviceLayer.GetBusinessTypes().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() });

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return View(model);
            }

            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }

            int cpId;
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {

                    CompanyProfile cp = new CompanyProfile
                    {
                        Address1 = model.Address1,
                        Address2 = model.Address2,
                        BusinessType = model.BusinessType,
                        City = model.City,
                        CompanyName = model.CompanyName,
                        OperatingDistance = model.OperatingDistance,
                        Phone = Util.ConvertPhoneForStorage(model.Phone),
                        PostalCode = model.PostalCode,
                        Published = true,
                        StateId = model.StateId
                    };

                    GeoLocator locator = new GeoLocator();

                    string state = _serviceLayer.GetStates().Where(x => x.Id == model.StateId).FirstOrDefault().Abbr;

                    if (model.Address1 == null || model.Address1 == string.Empty)
                    {
                        cp.GeoLocation = locator.GetFromCityStateZip(model.City, state, model.PostalCode);
                    }
                    else
                    {
                        cp.GeoLocation = locator.GetFromAddress(model.Address1, model.City, state, model.PostalCode);
                    }

                    // if we can create the company, create the user
                    if (_serviceLayer.CreateCompany(cp))
                    {
                        cpId = cp.Id;
                        string confirmationToken = _security.CreateUserAndAccount(
                            model.Email,
                            model.Password,
                            new
                            {
                                FirstName = model.FirstName,
                                LastName = model.LastName,
                                CompanyId = cp.Id
                            }, true);

                        _security.AddUserToRole(model.Email, "Manager");

                        //var businesstypes = _serviceLayer.GetBusinessTypes();

                        switch (model.BusinessType)
                        {
                            case BusinessType.GeneralContractor:
                                _security.AddUserToRole(model.Email, "general_contractor");
                                break;
                            case BusinessType.SubContractor:
                                _security.AddUserToRole(model.Email, "subcontractor");
                                break;
                            case BusinessType.Architect:
                                _security.AddUserToRole(model.Email, "architect");
                                break;
                            case BusinessType.Engineer:
                                _security.AddUserToRole(model.Email, "engineer");
                                break;
                            case BusinessType.Owner:
                                _security.AddUserToRole(model.Email, "owner_client");
                                break;
                            case BusinessType.MaterialsVendor:
                                _security.AddUserToRole(model.Email, "materials_vendor");
                                break;
                            case BusinessType.MaterialsMfg:
                                _security.AddUserToRole(model.Email, "materials_manufacturer");
                                break;
                            case BusinessType.Consultant:
                                _security.AddUserToRole(model.Email, "consultant");
                                break;
                        };

                        _emailer.SendConfirmationMail(model.FirstName, model.Email, confirmationToken);

                        return RedirectToAction("RegisterStepTwo", "Account");
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Exception", ex.Message);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }