public async Task <ActionResult> EmployeeRegister(EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = new Employee
                {
                    FirstName     = model.Employee.FirstName,
                    LastName      = model.Employee.LastName,
                    Phone         = model.Employee.Phone,
                    StreetAddress = model.Employee.StreetAddress,
                    ZipCode       = model.Employee.ZipCode,
                    Wage          = model.Employee.Wage
                };
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var empUser = user.Id;

                    employee.ApplicationUserId = user.Id;

                    db.Employee.Add(employee);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Roles"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> Register(EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee();
                if (_context.Employees.Count() == 0)
                {
                    employee.Role = "Administrator";
                }
                else
                {
                    employee.Role = "Employee";
                }
                employee.Username    = model.Username;
                employee.Password    = model.Password;
                employee.Email       = model.Email;
                employee.Firstname   = model.Firstname;
                employee.Lastname    = model.Lastname;
                employee.USN         = model.USN;
                employee.Address     = model.Address;
                employee.PhoneNumber = model.PhoneNumber;
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ListEmployees)));
            }
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Register(EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                IdentityUser createNewUser = new IdentityUser()
                {
                    UserName = model.Email,
                    Email    = model.Email
                };

                IdentityResult result = await _userManager.CreateAsync(createNewUser, model.Password);

                if (result.Succeeded)
                {
                    await _signInManager.PasswordSignInAsync(model.Email, model.Password, isPersistent : false, lockoutOnFailure : false);

                    return(RedirectToAction("Programming", "Welcome"));
                }

                foreach (var errors in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, errors.Description);
                }
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    FIO          = model.FIO,
                    UserName     = model.Email,
                    Email        = model.Email,
                    OpenPassword = model.Password
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var roles = new List <string>();
                    roles.Add(RoleNames.Employee);
                    roles.AddRange(model.GetSelectedRoles());

                    var resultRole = await _userManager.AddToRolesAsync(user, roles);

                    return(RedirectToAction(nameof(Index)));
                }
                AddErrors(result);
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult EmployeeRegister()
        {
            IEnumerable <mvcShopModel> shops;
            HttpResponseMessage        response = GlobalHttp.WebApiClient.GetAsync("Shops").Result;

            shops = response.Content.ReadAsAsync <IEnumerable <mvcShopModel> >().Result;
            var employee = new EmployeeRegisterViewModel();

            employee.ShopList = new List <Shop>();
            foreach (var shop in shops)
            {
                employee.ShopList.Add(new Shop {
                    Name = shop.ShopName
                });
            }
            employee.ShopList.Add(new Shop {
                Name = ""
            });
            //employee.ShopList.Add(new Shop { Name = "Fast2" });
            //employee.ShopList.Add(new Shop { Name = "Fast3" });



            return(View(employee));
        }
        public IActionResult AddEmployee(EmployeeRegisterViewModel model)
        {
            var UserId = HttpContext.Session.GetString("UserId");

            if (ModelState.IsValid)
            {
                var item = new Models.Account
                {
                    Branch       = _Employee.GetBranchById(int.Parse(model.Branch)),
                    Department   = _Employee.GetDepartmentById(int.Parse(model.Department)),
                    Company      = _Employee.GetCompanyById(int.Parse(model.Company)),
                    Position     = _Employee.GetPositionById(int.Parse(model.Position)),
                    Category     = _Employee.GetCategoryById(int.Parse(model.Category)),
                    EmployeeNo   = model.EmployeeNo,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    MiddleName   = model.MiddleName,
                    CreatedBy    = UserId,
                    CreationDate = DateTime.Now,
                };
                _Employee.Add(item);
                return(RedirectToAction("Index"));
            }
            else
            {
                model.Companies   = this.Companies();
                model.Branches    = this.Branches();
                model.Departments = this.Departments();
                model.Positions   = this.Positions();
                return(RedirectToAction("AddEmployee", model));
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult> EmployeeRegister(EmployeeRegisterViewModel model, string SelectedRole)
        {
            if (ModelState.IsValid)
            {
                String rolename = db.AppRoles.Find(SelectedRole).Name;

                model.EmpType = rolename;
                //Add fields to user here so they will be saved to do the database
                var user = new AppUser
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    MI          = model.MI,
                    SSN         = model.SSN,
                    Address     = model.Address,
                    City        = model.City,
                    State       = model.State,
                    ZipCode     = model.ZipCode,
                    PhoneNumber = model.PhoneNumber,
                    DOB         = model.DOB,
                    EmpType     = rolename,
                    //EmpType = model.EmpType,
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                db.SaveChanges();
                //String rolename = db.AppRoles.Find(SelectedRole).Name;

                //model.EmpType = rolename;

                //Once you get roles working, you may want to add users to roles upon creation
                await UserManager.AddToRoleAsync(user.Id, rolename);


                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            ViewBag.RoleOptions = GetAllRoles();
            return(View(model));
        }
        public async Task <IActionResult> EmployeeRegister(
            [Bind("FirstName", "LastName", "Email", "Password", "ConfirmPassword", "Streetaddress", "City", "Country", "Telephonenumber")]
            EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User
                {
                    UserName        = model.FirstName,
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    Birthday        = model.Birthday,
                    Streetaddress   = model.Streetaddress,
                    Zipcode         = model.Zipcode,
                    City            = model.City,
                    Country         = model.Country,
                    Telephonenumber = model.Telephonenumber,

                    Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                //IdentityResult roleResult = await _roleManager.CreateAsync(new IdentityRole("Employee"));

                if (result.Succeeded)
                {
                    bool checkRole = await _roleManager.RoleExistsAsync("Employee");

                    if (!checkRole)
                    {
                        var role = new IdentityRole();
                        role.Name = "Employee";
                        await _roleManager.CreateAsync(role);

                        await _userManager.AddToRoleAsync(user, "Employee");
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, "Employee");
                    }

                    //await _signManager.SignInAsync(user, false);
                    return(RedirectToAction("Login", "Account"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View());
        }
        public IActionResult AddEmployee()
        {
            var model = new EmployeeRegisterViewModel
            {
                Companies          = this.Companies(),
                Branches           = this.Branches(),
                Departments        = this.Departments(),
                Positions          = this.Positions(),
                EmployeeCategories = this.Categories(),
            };

            return(View(model));
        }
Exemplo n.º 10
0
        public async Task <ActionResult> CreateEmployee(EmployeeRegisterViewModel model)
        {
            string upgraded = await _adminRepository.GetUserStatusAsync(CurrentUser) ?? "";

            int numberOfEmployees = EmployeeManager.Users.Where(u => u.CompanyId == CurrentCompanyId).Count();

            if (numberOfEmployees >= 5 && !upgraded.Equals("active"))
            {
                return(RedirectToAction("Index", "Admin", new { message = "Please upgrade your account to add more employees." }));
            }

            if (ModelState.IsValid)
            {
                var user = new EmployeeUser
                {
                    UserName     = model.Username,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    PayRate      = model.Payrate,
                    OverTimeRate = model.OvertimeRate,
                    TaxRate      = model.TaxRate,
                    HireDate     = model.HireDate,
                    PhoneNumber  = model.Phone,
                    Address      = model.Address,
                    PayMethod    = model.PayMethod,

                    CompanyId   = CurrentCompanyId,
                    CompanyName = CurrentCompany,
                    IsAdmin     = false
                };

                var result = await EmployeeManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    result = await EmployeeManager.AddToRoleAsync(user.Id, "Employee");
                }

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Admin", new { message = "Employee created successfully." }));
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 11
0
        // GET: Administration/Employees/RegisterEmployee
        public IActionResult Register()
        {
            var companies =
                this.companiesService
                .GetAll <CompanyDropDownViewModel>()
                .Prepend(new CompanyDropDownViewModel {
                Id = string.Empty, Name = string.Empty
            });

            var sections =
                this.sectionsService
                .GetAll <SectionDropDownViewModel>()
                .Prepend(new SectionDropDownViewModel()
            {
                Id = null, Name = string.Empty
            });

            var teams =
                this.teamService
                .GetAll <TeamDropDownViewModel>()
                .Prepend(new TeamDropDownViewModel()
            {
                Id = null, Name = string.Empty
            });

            var users =
                this.userService
                .GetAll <ApplicationUserDropDownViewModel>()
                .Prepend(new ApplicationUserDropDownViewModel {
                Id = string.Empty, FullName = string.Empty
            });

            var viewModel = new EmployeeRegisterViewModel
            {
                Companies        = companies,
                Sections         = sections,
                Teams            = teams,
                ApplicationUsers = users,
            };

            return(this.View(viewModel));
        }
Exemplo n.º 12
0
        public async Task <ActionResult> RegisterEmployee(EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Luu thong tin dang ky vao table customer
                    Employee employee = new Employee
                    {
                        Name     = model.Name,
                        Address  = model.Address,
                        Phone    = model.Phone,
                        Email    = model.Email,
                        Position = model.Position,
                        UserId   = user.Id
                    };
                    db.Employees.Add(employee);
                    db.SaveChanges();

                    //Gán role cho user
                    await UserManager.AddToRoleAsync(user.Id, model.UserRoles);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }
            // If we got this far, something failed, redisplay form
            List <string> positions = new List <string> {
                "Director", "Manager", "Secretary", "Employee", "Trainee"
            };

            ViewBag.Positions = new SelectList(positions, model.Position);
            ViewBag.Roles     = new SelectList(db.AspNetRoles.Where(u => !u.Name.Contains("Admin")).ToList(), "Name", "Name", model.UserRoles);
            return(View(model));
        }
Exemplo n.º 13
0
        public async Task <string> RegisterAsync(EmployeeRegisterViewModel employee)
        {
            var applicationUser = new ApplicationUser
            {
                FullName    = employee.FullName,
                Position    = employee.Position,
                TeamId      = employee.TeamId,
                AddressId   = employee.AddressId,
                SectionId   = employee.SectionId,
                CompanyId   = employee.CompanyId,
                ManagerId   = employee.ManagerId,
                CreatedFrom = employee.CreatedFrom,
            };

            await this.applicationUserRepository.AddAsync(applicationUser);

            await this.applicationUserRepository.SaveChangesAsync();

            return(applicationUser.Id);
        }
Exemplo n.º 14
0
        public ActionResult CreateEmployee(string username)
        {
            if (username == null)
            {
                EmployeeRegisterViewModel model = new EmployeeRegisterViewModel
                {
                    LoggedUser    = CurrentUser,    //BaseViewModel
                    LoggedCompany = CurrentCompany, //BaseViewModel
                    LogoUrl       = CurrentLogoUrl, //BaseViewModel

                    HireDate = DateTime.Today
                };

                return(View(model));
            }

            var user = EmployeeManager.Users.FirstOrDefault(u => u.UserName == username);

            EmployeeUpdateModel employee = new EmployeeUpdateModel
            {
                LoggedUser    = CurrentUser,    //BaseViewModel
                LoggedCompany = CurrentCompany, //BaseViewModel
                LogoUrl       = CurrentLogoUrl, //BaseViewModel

                Username     = user.UserName,
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Payrate      = user.PayRate,
                OvertimeRate = user.OverTimeRate,
                Phone        = user.PhoneNumber,
                Address      = user.Address,
                TaxRate      = user.TaxRate,
                PayMethod    = user.PayMethod,
                PayMethods   = new List <PayMethod>()
                {
                    PayMethod.Hour, PayMethod.Day, PayMethod.Month, PayMethod.Year
                }
            };

            return(View("UpdateEmployee", employee));
        }
Exemplo n.º 15
0
        public async Task <ActionResult <EmployeeViewModel> > Register([FromBody] EmployeeRegisterViewModel employeeRegister)
        {
            if (employeeRegister.Email == null || employeeRegister.Email.Length < 10)
            {
                return(Ok("Email không hợp lệ."));
            }

            if (EmailCustomerExists(employeeRegister.Email) || EmailEmployeeExists(employeeRegister.Email))
            {
                return(Ok("Email đã tồn tại."));
            }
            if (employeeRegister.PassWord == null || employeeRegister.PassWord.Length < 6)
            {
                return(Ok("Mật khẩu không hợp lệ."));
            }
            var role = _context.Roles.Find(employeeRegister.RoleId);

            if (role == null)
            {
                return(Ok("Chức vụ không hợp lệ."));
            }


            var employee = employeeRegister.ToEmployee();

            _context.Employees.Add(employee);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(Ok("Thêm nhân viên thất bại."));
            }

            employee.PassWord = null;
            return(CreatedAtAction("GetEmployeeInfo", new { employeeId = employee.EmployeeId }, employee));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Register(EmployeeRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var Result = await userManager.CreateAsync(user, model.Password);

                if (Result.Succeeded)
                {
                    await signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("index", "home"));
                }
                foreach (var errors in Result.Errors)
                {
                    ModelState.AddModelError("", errors.Description);
                }
            }
            return(View(model));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Register(EmployeeRegisterViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            inputModel.CreatedFrom = this.userManager.GetUserAsync(this.User).Result.FullName;

            var existingЕmployeeId = this.userService.GetIdByFullName(inputModel.FullName);

            if (existingЕmployeeId == null)
            {
                var userId = await this.userService.RegisterAsync(inputModel);

                return(this.RedirectToAction(nameof(this.Details), new { id = userId }));
            }

            const string messageContent = EmployeeExist;

            return(this.RedirectToAction("Details", "Employees", new { id = existingЕmployeeId, message = messageContent }));
        }
        public IActionResult Edit(int id)
        {
            var item  = _Employee.GetEmployeeById(id);
            var model = new EmployeeRegisterViewModel
            {
                Id                 = item.Id.ToString(),
                FirstName          = item.FirstName,
                MiddleName         = item.MiddleName,
                LastName           = item.LastName,
                EmployeeNo         = item.EmployeeNo,
                Branch             = item.Branch.Id.ToString(),
                Company            = item.Company.Id.ToString(),
                Category           = item.Category.Id.ToString(),
                Department         = item.Department.Id.ToString(),
                Position           = item.Position.Id.ToString(),
                Companies          = this.Companies(),
                Branches           = this.Branches(),
                Departments        = this.Departments(),
                Positions          = this.Positions(),
                EmployeeCategories = this.Categories(),
            };

            return(View(model));
        }
Exemplo n.º 19
0
        public IActionResult Create()
        {
            var model = new EmployeeRegisterViewModel(0);

            return(View(model));
        }
Exemplo n.º 20
0
        public async Task <ActionResult> EmployeeRegister(EmployeeRegisterViewModel model)
        {
            mvcEmplyeeModel employee = new mvcEmplyeeModel();

            Console.WriteLine("I m here");
            if (ModelState.IsValid)
            {
                int shopID = 3;
                var user   = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                //Shop Detail
                IEnumerable <mvcShopModel> shops;
                HttpResponseMessage        response = GlobalHttp.WebApiClient.GetAsync("Shops").Result;
                shops = response.Content.ReadAsAsync <IEnumerable <mvcShopModel> >().Result;
                foreach (var shop in shops)
                {
                    if (shop.ShopName == model.ShopName)
                    {
                        shopID = shop.ShopId;
                    }
                }



                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    //Employee Detail
                    employee.EmpName     = model.EmployeeName;
                    employee.EmpEmail    = model.Email;
                    employee.EmpUsername = model.EmployeeName;
                    employee.ShopId      = shopID;
                    HttpResponseMessage respons = GlobalHttp.WebApiClient.PostAsJsonAsync("Employees", employee).Result;
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var         callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    MailMessage msg         = new MailMessage();
                    msg.From = new MailAddress("*****@*****.**");
                    msg.To.Add(new MailAddress(model.Email));
                    msg.Subject = "Verify Your Email";
                    msg.Body    = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>";

                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", Convert.ToInt32(587));
                    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "TijaratPOS000");
                    smtpClient.Credentials = credentials;
                    smtpClient.EnableSsl   = true;
                    smtpClient.Send(msg);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    TempData["SuccessMessage"] = "Please Verify Your Email Address!!";

                    return(RedirectToAction("Login"));
                }
                AddErrors(result);
            }
            TempData["AlertMessage"] = "Something Went Wrong!! May be User Exist with Same Email Address.";
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public EmployeeRegisterView()
 {
     InitializeComponent();
     DataContext = new EmployeeRegisterViewModel(this);
 }