public bool DeleteBusinessUser(BusinessUser businessUser)
        {
            try
            {
                BusinessUserTable.DeleteOnSubmit(businessUser);
                BusinessUserTable.Context.SubmitChanges();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public bool SaveBusinessUser(BusinessUser businessUser)
        {
            try
            {
                if (businessUser.BusinessUserId == 0)
                {
                    BusinessUserTable.InsertOnSubmit(businessUser);
                }
                else
                {
                    BusinessUserTable.Context.Refresh(RefreshMode.KeepCurrentValues, businessUser);
                }

                BusinessUserTable.Context.SubmitChanges();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        private StringBuilder GetBusinessDetailsForDisplay(BusinessUser business)
        {
            //var sb = GetUserDetailsForDisplay(business);
            var sb = new StringBuilder();

            return sb;
        }
        public ActionResult RegisterBusiness(BusinessRegisterModel model)
        {
            ViewBag.Register = "Register as a business";
            ViewBag.RegisterAction = "Register";
            ViewBag.Message = "Business.";

            if (!model.TermsAndConditions)
            {
                ModelState.AddModelError("TermsAndConditions", "You must agree to the terms and conditions to register.");
            }

            if (ModelState.IsValid)
            {
                if (model.Logo != null)
                {
                    // Attempt to register the user
                    try
                    {
                        var trmservice = new WebService.WCFWebServiceJson();
                        var util = new Utilities();

                        var business = new BusinessUser
                        {
                            Logo= util.RemoveSpaces(model.BusinessName) + "/" + model.Logo.FileName,
                            UserName = model.UserName,
                            Password = model.Password,
                            UserType = DomainModel.Entities.User.UserTypeList.Business,
                            BusinessName = model.BusinessName,
                            BusinessType = trmservice.GetAllBusinessTypes().Where(x => x.BusinessTypeId == model.BusinessType).FirstOrDefault(),
                            BusinessTypeId = model.BusinessType,
                            Address1 = model.Address1,
                            Address2 = model.Address2,
                            City = model.City,
                            PostCode = model.PostCode,
                            Country = model.Country,
                            TermsAndConditionsAccepted = model.TermsAndConditions,
                            CreatedDate = DateTime.Now
                        };

                        if (trmservice.RegisterBusiness(business, model.Logo))
                        {
                            WebSecurity.Login(model.UserName, model.Password);
                            return RedirectToAction("RegisterBusinessSuccess", "Account");
                        }
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("Error registering business", 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);
        }
        public bool RegisterBusiness(BusinessUser business, HttpPostedFileBase sourceFile)
        {
            bool isRegistered;

            using (var tranScope = new TransactionScope())
            {
                try
                {
                    // if the user is saved successfully it will return a userId which is always greater than 0
                    WebSecurity.CreateUserAndAccount(business.UserName, business.Password);
                    Roles.AddUserToRole(business.UserName, business.UserType.ToString());
                    business.UserId = WebSecurity.GetUserId(business.UserName);

                    // now create an account for this user
                    isRegistered = SaveBusiness(business);

                    if (isRegistered)
                    {
                        // now create an account for this user
                        isRegistered = SaveUserAccount(business, Account.AccountTypeList.business);

                        // save file locally to upload it
                        if (!UploadFileToS3(SaveFileLocally(sourceFile), util.RemoveSpaces(business.BusinessName) + "/", "master"))
                        {
                            return false;
                        }

                        tranScope.Complete();
                    }
                }
                catch
                {
                    return false;
                }
            }

            return (business.UserId > 0 && isRegistered);
        }
 private bool SaveBusiness(BusinessUser business)
 {
     try
     {
         return SqlBusinessUserRepository.SaveBusinessUser(business);
     }
     catch (Exception ex)
     {
         util.ErrorNotification(ex);
         throw;
     }
 }