コード例 #1
0
        public async Task <EmployeeResponseModel> CreateEmployee(EmployeeRequestModel employeeRequestModel)
        {
            var dbEmployee = await _employeesRepository.GetEmployeeByName(employeeRequestModel.Name);

            if (dbEmployee != null)
            {
                throw new Exception("Employee exists, try Login");
            }
            //var salt = CreateSalt();
            //var hashedPassword = CreateHashedPassword(employeeRequestModel.Password, salt);
            var employee = new Employees
            {
                Name        = employeeRequestModel.Name,
                Password    = employeeRequestModel.Password,
                Designation = employeeRequestModel.Designation,
            };
            var response = await _employeesRepository.AddAsync(employee);

            var createdEmployee = new EmployeeResponseModel
            {
                Id          = response.Id,
                Name        = response.Name,
                Designation = response.Designation,
            };

            return(createdEmployee);
        }
コード例 #2
0
 public Task <IActionResult> Add(Employees model)
 {
     return(Task.Factory.StartNew <IActionResult>(() =>
     {
         if (!ModelState.IsValid)
         {
             return Json(ExcutedResult.FailedResult("数据验证失败"));
         }
         EmployeesRepository.AddAsync(model, false);
         return Json(ExcutedResult.SuccessResult());
     }));
 }
コード例 #3
0
        public async Task <EntityActionOutcome> CreateEntityAsync(EmployeeInputData viewData)
        {
            var newEntity = _factory.Create(viewData);
            var validator = new EmployeeDataInputValidator();
            var result    = validator.Validate(viewData);

            if (result.IsValid == false)
            {
                return(EntityActionOutcome.MissingFullEntityData);
            }

            var upsertSuccessful = await _repository.AddAsync(newEntity);

            if (upsertSuccessful == null)
            {
                return(EntityActionOutcome.CreateFailed);
            }

            return(EntityActionOutcome.Success);
        }
コード例 #4
0
 public async Task HandleAsync(CreateEmployee command, ICorrelationContext context)
 {
     var employee = new Employee(command.Id, command.FirstName, command.SecondName, command.Surname,
                                 command.Birthday, command.EmployeeStatus, command.EmployeePosition);
     await _employeeRepository.AddAsync(employee);
 }
コード例 #5
0
 public async Task <Employees> CreateEmployees(Employees employees)
 {
     return(await _employeesRepository.AddAsync(employees));
 }