コード例 #1
0
        public ActionResult Create(EmployeeInputModel inputModel)
        {
            var newEmployee = new Employee();
            newEmployee.CompanyId = "1";
            newEmployee.SerialNumber = inputModel.Serial1;
            newEmployee.FirstName = inputModel.FirstName;
            newEmployee.LastName = inputModel.LastName;

            _employeeUnitOfWork.Initialize();
            _employeeUnitOfWork.Insert(newEmployee);
            _employeeUnitOfWork.Execute();

            return RedirectToAction("Index");
        }
コード例 #2
0
        public ActionResult Edit(EmployeeInputModel inputModel)
        {
            var employee = _employeeRepository.FindEmployeeById("1", inputModel.OriginalSerial);
            if (employee == null)
            {
                return new HttpNotFoundResult();
            }

            if (inputModel.OriginalSerial != inputModel.Serial1)
            {
                _employeeUnitOfWork.Initialize();
                _employeeUnitOfWork.Delete(employee);
                _employeeUnitOfWork.Execute();

                employee = new Employee();
                employee.CompanyId = "1";
            }

            employee.SerialNumber = inputModel.Serial1;
            employee.FirstName = inputModel.FirstName;
            employee.LastName = inputModel.LastName;

            _employeeUnitOfWork.Initialize();
            _employeeUnitOfWork.InsertOrReplace(employee);
            _employeeUnitOfWork.Execute();

            return RedirectToAction("Index");
        }
コード例 #3
0
        public ActionResult Import(ImportInputModel inputModel)
        {
            var existingEmployees = _employeeRepository.GetEmployeesInCompany("1");
            var rows = inputModel.ImportText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            _employeeUnitOfWork.Initialize();

            foreach (var row in rows)
            {
                var parts = row.Split(',');
                var serial = parts[0];
                if (parts.Length != 3 || existingEmployees.Any(e => e.SerialNumber == serial))
                {
                    continue;
                }

                var newEmployee = new Employee();
                newEmployee.CompanyId = "1";
                newEmployee.SerialNumber = serial;
                newEmployee.FirstName = parts[1];
                newEmployee.LastName = parts[2];

                _employeeUnitOfWork.Insert(newEmployee);

            }
            _employeeUnitOfWork.Execute();
            return RedirectToAction("Index");
        }