예제 #1
0
파일: Employees.cs 프로젝트: tymish/api
        public void AddEmployee_UseCase()
        {
            Employee employee = new Employee {
                FirstName = "Kazuto",
                LastName  = "Kirigaya",
                Email     = "*****@*****.**",
                HourlyPay = 25
            };

            Employee employeeWithId = employee;

            employeeWithId.Id = 1;

            AddEmployeeResponse response = new AddEmployeeResponse {
                Data = employeeWithId
            };

            var mockAddEmployee = new Mock <IAddEmployee>();

            mockAddEmployee.Setup(m => m.Execute(employee)).Returns(response);

            var result = mockAddEmployee.Object.Execute(employee);

            mockAddEmployee.Verify(e => e.Execute(employee));
            Assert.Equal <Employee>(result.Data, employeeWithId);
        }
예제 #2
0
        public override async Task <AddEmployeeResponse> AddEmployee(AddEmployeeRequest request, ServerCallContext context)
        {
            var reslut   = new AddEmployeeResponse();
            var employee = await _employeeRepository.Add(request.Employee);

            reslut.Employee = employee;

            return(reslut);
        }
예제 #3
0
파일: AddEmployee.cs 프로젝트: tymish/api
        public AddEmployeeResponse Execute(Employee employee)
        {
            AddEmployeeResponse response = new AddEmployeeResponse();

            try
            {
                response.Data = _repository.Add <Employee>(employee);
                response.MarkSuccessful();
            }
            catch (Exception e)
            {
                response.AddError(e.Message);
            }
            finally
            {
                // Log Execution
            }
            return(response);
        }
예제 #4
0
        public IActionResult AddEmployee([FromBody] AddEmployeeRequest request)
        {
            var response = new AddEmployeeResponse();

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Where(e => e.Value.Errors.Count > 0).Select(ee => ee.Value.Errors.First().ErrorMessage);
                response.ErrorResponse = Helpers.Helper.ConvertToErrorResponse(errors.FirstOrDefault(), ErrorsType.ValidationError.ToString(), ErrorMessageType.Validation.ToString());
                return(BadRequest(response));
            }

            var result = _dbRepository.AddEmployee(request.Name, request.Address, request.Salary, request.DepartmentId);

            if (result > 0)
            {
                response.Result  = true;
                response.Success = true;
            }
            else
            {
                response.ErrorResponse = Helpers.Helper.ConvertToErrorResponse("Some error occured in adding employee..", ErrorsType.DatabaseError.ToString(), ErrorMessageType.Error.ToString());
            }
            return(Ok(response));
        }