public async Task <ActionResult> CreateEmployee(EmployeeCreateVM model) { model.AvailableRoles = new HashSet <string>(await _staffManager.StaffRoles()); if (!ModelState.IsValid) { return(View(model)); } IdentityResult result = await _staffManager.CreateAsync(new EmployeeCreateDTO { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, Roles = model.Roles }); if (result.Succeeded) { return(RedirectToAction(nameof(Staff))); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View(model)); }
public async Task <ActionResult> Create() { var vm = new EmployeeCreateVM(); SetEmployeeDefaults(vm); await SetEmployeePositionSelectListAsync(vm.PositionId ?? 0); return(View(vm)); }
public void AddEmployee(EmployeeCreateVM employeeCreateVM) { context.Employees.Add(new Employee { Name = employeeCreateVM.Name, Email = employeeCreateVM.Email }); context.SaveChanges(); }
public async Task <ActionResult> CreateEmployee() { var viewModel = new EmployeeCreateVM { AvailableRoles = new HashSet <string>(await _staffManager.StaffRoles()) }; return(View(viewModel)); }
public IActionResult Create(EmployeeCreateVM employeeCreateVM) { if (!ModelState.IsValid) { return(View(employeeCreateVM)); } service.AddEmployee(employeeCreateVM); return(RedirectToAction(nameof(Index))); }
public void AddEmployee(EmployeeCreateVM viewModel) { //employee.Id = employeeCounter++; context.Employees.Add(new Employee { Name = viewModel.Name, Email = viewModel.Email, //CompanyId = viewModel.CompanyId }); context.SaveChanges(); }
private string ProcessUploadFile(EmployeeCreateVM model) { string uniqeFileName = null; if (model.Photo != null) { string uploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); // to save in webroot/images uniqeFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; //unique files name string filePath = Path.Combine(uploadFolder, uniqeFileName); model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } return(uniqeFileName); }
private string ProcessUploadedPhoto(EmployeeCreateVM viewModel) { string uniqueFileName = null; if (viewModel.Photo != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid() + "_" + viewModel.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { viewModel.Photo.CopyTo(fileStream); } } return(uniqueFileName); }
public ActionResult Create(EmployeeCreateVM viewModel) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedPhoto(viewModel); Employee newEmployee = new Employee { Name = viewModel.Name, Email = viewModel.Email, Department = viewModel.Department, PhotoPath = uniqueFileName }; _employeeRepository.Add(newEmployee); return(RedirectToAction("Details", new { id = newEmployee.Id })); } return(View()); }
public ActionResult Create(EmployeeCreateVM model) { if (!ModelState.IsValid) { return(View(model)); } Employee employee = _mapper.Map <Employee>(model); if (string.IsNullOrEmpty(employee.Photo)) { employee.Photo = _employeeService.GetDefaultPhoto(); } Employee addedEmployee = _employeeService.Add(employee); return(RedirectToAction(nameof(Details), new { id = addedEmployee.ID })); }
public async Task <ActionResult> EditEmployee(string id) { ApplicationUserDTO user = await _staffManager.GetAsync(id); if (user == null || user.Id != id) { return(NotFound()); } var viewModel = new EmployeeCreateVM { FirstName = user.FirstName, MiddleName = user.MiddleName, LastName = user.LastName, Email = user.Email, Roles = new HashSet <string>(user.ApplicationRoles.Select(r => r.Name)), AvailableRoles = new HashSet <string>(await _staffManager.StaffRoles()) }; return(View(viewModel)); }
public async Task <ActionResult> Create(EmployeeCreateVM vm) { if (ModelState.IsValid) { var entity = vm.ToEmployee(); //TODO: Implement password reset and send a password recovery mail var user = vm.ToUser(); IdentityResult result = await CreateUserUnique(user, vm.NewPassword); if (result.Succeeded) { await AddToRoleAsync(user, SecurityRoles.Clerk); entity.AspNetUserId = user.Id; entity.IsActive = true; DataContext.Employees.Add(entity); await DataContext.SaveChangesAsync(this); await UserManager.SetLockoutEnabledAsync(user.Id, true); } else { throw new Exception(string.Format("User {0} could not be created! See errors: {1}", user.UserName, result.Errors)); } await DataContext.RefreshDesignerDtoList(); await DataContext.RefreshMerchandiserDtoList(); return(RedirectToAction("Details", new { id = entity.Id })); } await SetEmployeePositionSelectListAsync(vm.PositionId ?? 0); return(View(vm)); }
protected void SetEmployeeDefaults(EmployeeCreateVM employee) { employee.NewPassword = "******"; }
public ActionResult Create() { EmployeeCreateVM model = new EmployeeCreateVM(); return(View(model)); }