Пример #1
0
        public static async Task AddEmployeeLoginAsync(eStoreDbContext db, Employee employee, UserManager <AppUser> userManager)
        {
            if (employee != null)
            {
                if (employee.IsWorking)
                {
                    await UserAdmin.AddUserAsync(userManager, employee);
                }

                //{


                //    //TODO:    await UserAdmin.AddEmployeeUserAsync(db, employee.StaffName, employee.EmployeeId);

                //}
            }
            else
            {
                throw new Exception();
            }
        }
        public async Task <IActionResult> Create([Bind("EmployeeId,StaffName,MobileNo,JoiningDate,LeavingDate,IsWorking,Category")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                if (employee.Category == EmpType.StoreManager)
                {
                    await UserAdmin.AddUserAsync(_userManager, employee.StaffName, true);
                }
                else
                {
                    await UserAdmin.AddUserAsync(_userManager, employee.StaffName, false);
                }
                //TODO: Implement add employee level security and permissions

                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView(employee));
        }