public static BE.AccountViewModel BuildAccountViewModel(
			DA.Client client, DA.CityStateZip cityStateZip, DA.PaymentInfo paymentInfo)
        {
            BE.AccountViewModel account = new BE.AccountViewModel()
            {
                ClientGuid = client.ClientGuid,
                ClientID = client.ClientID,
                ClientName = client.ClientName,
                PhoneNumber = client.PhoneNumber,
                Email = client.Email,
                Address = client.Address,
                FederatedID = client.FederatedID,
                FederatedKey = client.FederatedKey,
                FederatedIDProvider = client.FederatedIDProvider,
                CityStateZipGuid = cityStateZip.CityStateZipGuid,
                City = cityStateZip.City,
                State = cityStateZip.State,
                ZipCode = cityStateZip.ZipCode,
                PaymentInfoGuid = paymentInfo.PaymentInfoGuid,
                PaymentInfoID = paymentInfo.PaymentInfoID,
                AmazonToken = paymentInfo.AmazonToken,
                PauseAccount = client.AccountPaused,
                IsWaiverd=client.IsWaiverd,
                FreeDays=client.FreeDays,
                AccountBalance=client.Credits,
                IsSuspended=client.IsSuspended,
                IsFlagged=client.IsFlagged,
                IsActive=client.IsActive

            };
            return account;
        }
        public ActionResult AccountToggle(AccountViewModel account)
        {
            ClientLogic clientLogic = new ClientLogic();
            Client client = clientLogic.GetClientByClientGuid(account.ClientGuid);
            if (null == client)
            {
                return RedirectToAction("See");
            }
            // toggle account paused flag
            client.AccountPaused = !account.PauseAccount;
            clientLogic.UpdateClient(client);

            return RedirectToAction("See");
        }
        private void SaveAccount(ClientLogic clientLogic, AccountViewModel account, MembershipUser user, bool insert)
        {
            // Call business logic to insert the data.
            // todo: move to mapping
            CityStateZip cityStateZip = new CityStateZip
            {
                City = account.City,
                State = account.State,
                ZipCode = account.ZipCode
            };
            this.AddCityStateZipToAccount(account, cityStateZip);

            PaymentInfo paymentInfo = new PaymentInfo
            {
                AmazonToken = User.Identity.Name
            };
            this.AddPaymentInfoToAccount(account, paymentInfo);

            Client client = new Client();
            client.ClientName = account.ClientName;
            client.PhoneNumber = account.PhoneNumber;
            client.Email = user.UserName;
            client.Address = account.Address;
            client.CityStateZipGuid = account.CityStateZipGuid;
            client.PaymentInfoGuid = account.PaymentInfoGuid;
            // pause account - in create view is always false
            client.AccountPaused = account.PauseAccount;
            if (insert)
            {
                if (SessionHandler.Current.GitAssertion != null)
                {
                    GitAssertion assertion = SessionHandler.Current.GitAssertion;
                    client.FederatedIDProvider = assertion.Authority;
                    client.FederatedID = assertion.Identifier;
                    client.FederatedKey = user.ProviderUserKey.ToString();
                }

                client = clientLogic.InsertClient(client);
                account.ClientGuid = client.ClientGuid;
                account.ClientID = client.ClientID;
            }
            else
            {
                client.IsWaiverd = account.IsWaiverd;
                client.FreeDays = account.FreeDays;
                client.Credits = account.AccountBalance;
                client.IsSuspended = account.IsSuspended;
                client.IsActive = account.IsActive;
                client.ClientGuid = account.ClientGuid; // Had to add this......
                clientLogic.UpdateClient(client);
            }
        }
        private void AddPaymentInfoToAccount(AccountViewModel account, PaymentInfo paymentInfo)
        {
            Common.ValidateArgument<AccountViewModel>(account, "account");
            Common.ValidateArgument<PaymentInfo>(paymentInfo, "paymentInfo");

            PaymentInfoLogic piLogic = new PaymentInfoLogic();
            PaymentInfo existingPaymentInfo = piLogic.GetPaymentInfoByPaymentInfoGuid(paymentInfo.PaymentInfoGuid);
            if (existingPaymentInfo == null || existingPaymentInfo.PaymentInfoGuid == Guid.Empty)
            {
                paymentInfo = piLogic.InsertPaymentInfo(paymentInfo);
            }
            else
            {
                paymentInfo.PaymentInfoGuid = existingPaymentInfo.PaymentInfoGuid;
                piLogic.UpdatePaymentInfo(paymentInfo);
                paymentInfo = piLogic.GetPaymentInfoByPaymentInfoGuid(paymentInfo.PaymentInfoGuid);
            }

            account.PaymentInfoGuid = paymentInfo.PaymentInfoGuid;
        }
        private void AddCityStateZipToAccount(AccountViewModel account, CityStateZip cityStateZip)
        {
            Common.ValidateArgument<AccountViewModel>(account, "account");
            Common.ValidateArgument<CityStateZip>(cityStateZip, "cityStateZip");

            CityStateZipLogic cszLogic = new CityStateZipLogic();
            cityStateZip = cszLogic.InsertCityStateZip(cityStateZip);
            account.CityStateZipGuid = cityStateZip.CityStateZipGuid;
        }
        public ActionResult Edit(AccountViewModel account)
        {
            if (!ModelState.IsValid)
            {
                return View(account);
            }

            // Call business logic to insert the data.
            ClientLogic clientLogic = new ClientLogic();
            Client possibleClient = clientLogic.GetClientByEmail(account.Email);

            if (null == possibleClient)
            {
                return RedirectToAction("See");
            }

            this.SaveAccount(clientLogic, account, Membership.GetUser(), false);
            return RedirectToAction("See");
        }
        public ActionResult Create(AccountViewModel account)
        {
            // todo: implement some create account wizard when have more information
            if (!ModelState.IsValid)
            {
                return View(account);
            }

            // If logged in, show the appropriate view.
            var user = Membership.GetUser();
            if (user == null)
            {
                return RedirectToAction("Create");
            }

            ClientLogic clientLogic = new ClientLogic();
            // UserName is the email address they signed in with.
            Client possibleClient = clientLogic.GetClientByEmail(user.UserName);

            // If an account already exists for the user, show them the See page.
            if (null != possibleClient)
            {
                return RedirectToAction("See");
            }

            this.SaveAccount(clientLogic, account, user, true);
            return RedirectToAction("See");
        }