Пример #1
0
        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));
        }
Пример #2
0
        public async Task <ActionResult> Create()
        {
            var vm = new EmployeeCreateVM();

            SetEmployeeDefaults(vm);
            await SetEmployeePositionSelectListAsync(vm.PositionId ?? 0);

            return(View(vm));
        }
Пример #3
0
 public void AddEmployee(EmployeeCreateVM employeeCreateVM)
 {
     context.Employees.Add(new Employee
     {
         Name  = employeeCreateVM.Name,
         Email = employeeCreateVM.Email
     });
     context.SaveChanges();
 }
Пример #4
0
        public async Task <ActionResult> CreateEmployee()
        {
            var viewModel = new EmployeeCreateVM
            {
                AvailableRoles = new HashSet <string>(await _staffManager.StaffRoles())
            };

            return(View(viewModel));
        }
Пример #5
0
 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();
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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());
        }
Пример #10
0
        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 }));
        }
Пример #11
0
        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));
        }
Пример #12
0
        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));
        }
Пример #13
0
 protected void SetEmployeeDefaults(EmployeeCreateVM employee)
 {
     employee.NewPassword = "******";
 }
Пример #14
0
        public ActionResult Create()
        {
            EmployeeCreateVM model = new EmployeeCreateVM();

            return(View(model));
        }