public IActionResult Edit(EmployeeCreateView employee)
        {
            if (ModelState.IsValid)
            {
                string unicFileName = null;
                if (employee.photoFile != null)
                {
                    unicFileName = FileProcessing(employee);
                }
                if (employee.existingPhotoPath != null)
                {
                    string existngPath = Path.Combine(environment.WebRootPath, "images", employee.existingPhotoPath);
                    System.IO.File.Delete(existngPath);
                }

                Employee updateEmployee = _IemployeeRepository.GetEmpoyee(employee.Id);

                updateEmployee.Name       = employee.Name;
                updateEmployee.Email      = employee.Email;
                updateEmployee.Department = employee.Department;
                updateEmployee.Photo      = unicFileName;
                _IemployeeRepository.Update(updateEmployee);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
예제 #2
0
        public async Task <IdentityResult> CreateEmployeeUserAsync(EmployeeCreateView model, Company company)
        {
            string          DEFAULT_NEW_EMPLOYEE_PASSWORD = company.CompanyName.ToUpper() + "123";;
            ApplicationUser employee = new ApplicationUser {
                Email = model.Email, CompanyID = company.ID, UserName = model.Email
            };
            var user = new EmployeeUser {
                UserName = model.Email, Email = model.Email, CompanyID = company.ID, PrimaryContact = false
            };
            var result = await _userManager.CreateAsync(user, DEFAULT_NEW_EMPLOYEE_PASSWORD);

            if (result.Succeeded)
            {
                company.Team.Employees.Add(user);
                await _context.SaveChangesAsync();

                await _userManager.AddToRoleAsync(user, AppRole.SHIPPER);

                //confirm email for the user
                await ConfirmUserEmail(user);

                await _emailSender.SendEmailAsync(model.Email, "You have been created an accout",
                                                  $"Please log into the system with the default password " + DEFAULT_NEW_EMPLOYEE_PASSWORD + " , please dont forget to change it ");
            }
            return(result);
        }
        public IActionResult Create(EmployeeCreateView employee)
        {
            if (ModelState.IsValid)
            {
                string unicFileName = null;
                if (employee.photoFile != null)
                {
                    string UpLoadFolder = Path.Combine(environment.WebRootPath, "images");
                    unicFileName = Guid.NewGuid().ToString() + "_" + employee.photoFile.FileName;
                    string filePath = Path.Combine(UpLoadFolder, unicFileName);
                    employee.photoFile.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                Employee newEmployee = new Employee()
                {
                    Name       = employee.Name,
                    Email      = employee.Email,
                    Department = employee.Department,
                    Photo      = unicFileName
                };
                _IemployeeRepository.Add(newEmployee);
                return(RedirectToAction("Details", new { id = newEmployee.Id }));
            }

            return(View());
        }
예제 #4
0
        public IActionResult Create(EmployeeCreateView employee)
        {
            if (ModelState.IsValid)
            {
                string filepath = null;
                if (employee.Photo != null)
                {
                    string uploads = Path.Combine(hosting_Environment.WebRootPath, "images");
                    filepath = Guid.NewGuid().ToString() + "_" + employee.Photo.FileName;
                    string path = Path.Combine(uploads, filepath);
                    employee.Photo.CopyTo(new FileStream(path, FileMode.Create));
                }

                Employee newEmployee = new Employee
                {
                    Name     = employee.Name,
                    Email    = employee.Email,
                    Dep      = employee.Dep,
                    EmpPhoto = filepath
                };

                employee_Repo.Add(newEmployee);

                return(RedirectToAction("details", new { id = newEmployee.Id }));
            }

            return(View());
        }
        static void Main(string[] args)
        {
            bool endApplication = false;

            Employees employees = new Employees();

            EmployeeRecordsView employeeRecordsView = EmployeeObjectFactory.EmployeeRecordsViewObject(employees);


            while (!endApplication)
            {
                Console.Clear();

                Console.WriteLine(EmployeeCommonOutputText.GetApplicationHeading());

                employeeRecordsView.RunRecordsView();

                Console.WriteLine();
                Console.WriteLine();

                Console.WriteLine(EmployeeCommonOutputText.GetInstructions());

                ConsoleKey instructionKey = Console.ReadKey().Key;

                switch (instructionKey)
                {
                case ConsoleKey.C:
                    EmployeeCreateView employeeCreateView = EmployeeObjectFactory.EmployeeCreateViewObject(employees);
                    employeeCreateView.RunCreateView();
                    break;

                case ConsoleKey.R:
                    EmployeeReadView employeeReadView = EmployeeObjectFactory.EmployeeReadViewObject(employees);
                    employeeReadView.RunReadView();
                    break;

                case ConsoleKey.U:
                    Console.Clear();
                    Console.WriteLine("Update functionality not yet implemented.");
                    Console.ReadKey();
                    break;

                case ConsoleKey.D:
                    Console.Clear();
                    Console.WriteLine("Delete functionality not yet implemented.");
                    Console.ReadKey();
                    break;

                default:

                    endApplication = true;
                    break;
                }
            }



            Console.ReadKey();
        }
        public static EmployeeCreateView EmployeeCreateViewObject(Employees employees)
        {
            if (_employeeCreateView == null)
            {
                _employeeCreateView = new EmployeeCreateView(employees);
            }

            return(_employeeCreateView);
        }
        private string FileProcessing(EmployeeCreateView employee)
        {
            string unicFileName;
            string UpLoadFolder = Path.Combine(environment.WebRootPath, "images");

            unicFileName = Guid.NewGuid().ToString() + "_" + employee.photoFile.FileName;
            string filePath = Path.Combine(UpLoadFolder, unicFileName);

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                employee.photoFile.CopyTo(fileStream);
            }
            return(unicFileName);
        }
        public async Task <IActionResult> AddEmployee(EmployeeCreateView model)
        {
            var result = await userService.CreateEmployeeUserAsync(model, company);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
            return(View(model));
        }
        public ViewResult Edit(int Id)
        {
            Employee employee = _IemployeeRepository.GetEmpoyee(Id);

            if (employee == null)
            {
                return(View("EmployeeNotFound", Id));
            }
            EmployeeCreateView editEmployee = new EmployeeCreateView()
            {
                Id         = employee.Id,
                Name       = employee.Name,
                Department = employee.Department,
                Email      = employee.Email,
                Photo      = employee.Photo
            };

            return(View(editEmployee));
        }
예제 #10
0
        public IActionResult AddEmployee()
        {
            EmployeeCreateView model = new EmployeeCreateView();

            return(View(model));
        }
 public Task <IdentityResult> CreateEmployeeUserAsync(EmployeeCreateView model, Company company)
 {
     employeesCreated += 1;
     return(Task.FromResult(IdentityResult.Success));
 }