Exemple #1
0
        public async Task <ActionResult> Add([Bind(Include = "Email, Name, Password, ConfirmPassword")] AddEmployeeBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    Name     = model.Name
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    this.UserManager.AddToRole(user.Id, "Admin");
                    this._service.AddAdmin(model, user);

                    return(RedirectToAction("All"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public void AddEmployee(AddEmployeeBindingModel model, ApplicationUser appUser)
        {
            ApplicationUser user     = this.Context.Users.Find(appUser.Id);
            Employee        employee = new Employee()
            {
                ApplicationUser = user
            };

            this.Context.Employees.Add(employee);
            this.Context.SaveChanges();
        }
        public void AddAdmin(AddEmployeeBindingModel model, ApplicationUser appUser)
        {
            ApplicationUser user  = this.Context.Users.Find(appUser.Id);
            Admin           admin = new Admin()
            {
                ApplicationUser = user
            };

            this.Context.Admins.Add(admin);
            this.Context.SaveChanges();
        }