/// <summary>
        /// Step 8
        /// </summary>
        /// <returns></returns>
        public ActionResult AddAccounts(int id)
        {
            if (id == 0)
            {
                Message = "Workgroup must be created before proceeding";
                return(this.RedirectToAction(a => a.CreateWorkgroup()));
            }
            ViewBag.StepNumber = 8;
            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            if (workgroup.Administrative)
            {
                return(this.RedirectToAction <WorkgroupController>(a => a.Index(false)));
            }
            if (workgroup.SyncAccounts)
            {
                return(this.RedirectToAction(a => a.Vendors(id)));
            }
            var viewModel = WorkgroupAccountModel.Create(Repository, workgroup);

            return(View(viewModel));
        }
        public ActionResult AddAccounts(int id, WorkgroupAccount workgroupAccount, string account_search)
        {
            ViewBag.StepNumber = 8;
            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            if (workgroupAccount != null && workgroupAccount.Account == null)
            {
                workgroupAccount.Account = _repositoryFactory.AccountRepository.GetNullableById(account_search);
            }


            if (workgroupAccount == null || workgroupAccount.Account == null || string.IsNullOrWhiteSpace(workgroupAccount.Account.Id))
            {
                if (workgroupAccount == null)
                {
                    workgroupAccount.Account = new Account();
                }
                ModelState.Clear();
                if (!string.IsNullOrWhiteSpace(account_search))
                {
                    ModelState.AddModelError("WorkgroupAccount.Account", "Account not found.");
                }
                else
                {
                    ModelState.AddModelError("WorkgroupAccount.Account", "Select Account or skip.");
                }
                var viewModel1 = WorkgroupAccountModel.Create(Repository, workgroup, workgroupAccount);
                return(View(viewModel1));
            }

            var workgroupAccountToCreate = new WorkgroupAccount {
                Workgroup = workgroup
            };

            //Mapper.Map(workgroupAccount, workgroupAccountToCreate);//Mapper was causing me an exception JCS
            workgroupAccountToCreate.Account        = workgroupAccount.Account;
            workgroupAccountToCreate.AccountManager = workgroupAccount.AccountManager;
            workgroupAccountToCreate.Approver       = workgroupAccount.Approver;
            workgroupAccountToCreate.Purchaser      = workgroupAccount.Purchaser;

            ModelState.Clear();
            workgroupAccountToCreate.TransferValidationMessagesTo(ModelState);

            if (_workgroupAccountRepository.Queryable.Any(a => a.Workgroup.Id == workgroup.Id && a.Account.Id == workgroupAccountToCreate.Account.Id))
            {
                ModelState.AddModelError("WorkgroupAccount.Account", "Account already exists for this workgroup.");
            }
            if (ModelState.IsValid)
            {
                _workgroupAccountRepository.EnsurePersistent(workgroupAccountToCreate);
                Message = "Workgroup account saved.";
                //return this.RedirectToAction("Accounts", new {id = id});
                return(this.RedirectToAction(a => a.Accounts(id)));
            }

            var viewModel = WorkgroupAccountModel.Create(Repository, workgroup, workgroupAccountToCreate);

            return(View(viewModel));
        }