public ActionResult Create(BureauUsersViewModel model)
        {
            try
            {
                //await ValidateUserExists(clientUser.User);
                //ModelState.RemoveError<ClientUserViewModel>(e => e.User.Role);
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser
                    {
                        UserName       = model.User.Username,
                        Email          = model.User.Email,
                        EmailConfirmed = false,
                        Name           = model.User.Name
                    };

                    // Add Client Role
                    var roleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>();
                    var roleId      = roleManager.Roles.FirstOrDefault(r => r.Name == "Bureau").Id;
                    user.Roles.Add(new IdentityUserRole {
                        UserId = user.Id, RoleId = roleId
                    });

                    var result = UserManager.Create(user);
                    if (result.Succeeded)
                    {
                        var newUser          = UserManager.FindByName(user.UserName);
                        var bureauAspNetUser = new AspNetUserBureau
                        {
                            BureauId     = model.BureauId,
                            AspNetUserId = newUser.Id
                        };
                        _payrollBureauBusinessService.CreateAspNetUserBureau(bureauAspNetUser);
                        return(RedirectToAction("Edit", new { bureauId = model.BureauId, userId = newUser.Id }));
                    }

                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("CreateUserError", error);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("CreateUserError", ex.Message);
            }
            var bureau = _payrollBureauBusinessService.RetrieveBureau(model.BureauId);

            model.BureauId   = bureau.BureauId;
            model.BureauName = bureau.Name;
            return(View(model));
        }
        public ActionResult Create(BureauViewModel viewModel)
        {
            try
            {
                //create Bureau
                var userId = User.Identity.GetUserId();
                viewModel.Bureau.CreatedBy = userId;
                var bureau = _payrollBureauBusinessService.CreateBureau(viewModel.Bureau);
                if (!bureau.Succeeded)
                {
                    foreach (var error in bureau.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                    return(View(viewModel));
                }

                //create Bureau user and role
                var user = new ApplicationUser
                {
                    UserName = viewModel.Email,
                    Email    = viewModel.Email,
                };

                var roleId = RoleManager.Roles.FirstOrDefault(r => r.Name == "Bureau").Id;
                user.Roles.Add(new IdentityUserRole {
                    UserId = user.Id, RoleId = roleId
                });
                var result = UserManager.Create(user, "Inland12!");
                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                }

                //create AspNetUser Bureau
                _payrollBureauBusinessService.CreateAspNetUserBureau(bureau.Entity.BureauId, user.Id);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex);
            }
            return(RedirectToAction("Index", "Bureau"));
        }