public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationDbContext db  = new ApplicationDbContext();
                var workplace = db.Workplaces.Find(model.WorkplaceDropDown);
                var department = db.Departments.Find(model.DepartmentsDropDown);
                // Create a local login before signing in the user
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    DisplayName = model.DisplayName,
                    FacebookProfile = model.FacebookProfile,
                    Avatar = "default.png"
                };
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);

                    var registeredUser = db.Users.Find(user.Id);
                    if (department != null)
                    {
                        registeredUser.Department = department;
                    }
                    if (workplace != null)
                    {
                        registeredUser.Workplace = workplace;
                    }
                    db.SaveChanges();
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    DisplayName = model.DisplayName,
                    FacebookProfile = model.FacebookProfile,
                };
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

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