public async Task <IActionResult> Put([FromBody] Address address)
        {
            bool employeeExists = await _employee.Exists(EmployeeQueries.EmployeeExists(address.EmployeeId));

            if (!employeeExists)
            {
                return(StatusCode(StatusCodes.Status406NotAcceptable, new { message = "Employee not exists." }));
            }

            var result = await _address.Add(address);

            return(StatusCode(StatusCodes.Status200OK, new { address = result }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put([FromBody] Employee employee)
        {
            //bool employeeExists = await _employeeService.Exists(x => x.Id == employee.Id);
            bool employeeExists = await _employeeService.Exists(EmployeeQueries.EmployeeExists(employee.Id.Value));

            if (!employeeExists)
            {
                return(StatusCode(StatusCodes.Status406NotAcceptable, new { message = "Employee not exists." }));
            }

            var alteredEmployee = await _employeeService.Alter(employee);

            return(StatusCode(StatusCodes.Status200OK, new { employee = alteredEmployee }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Get(Guid?id)
        {
            //bool employeeExists = await _employeeService.Exists(x => x.Id == id);
            bool employeeExists = await _employeeService.Exists(EmployeeQueries.EmployeeExists(id));

            if (!employeeExists)
            {
                return(StatusCode(StatusCodes.Status406NotAcceptable, new { message = "Employee not exists." }));
            }

            var employee = await _employeeService.FindOne(x => x.Id == id);

            return(StatusCode(StatusCodes.Status200OK, new { selectedEmployee = employee }));
        }
        public async Task <IActionResult> Delete([FromBody] DeleteAddress address)
        {
            bool employeeExists = await _employee.Exists(EmployeeQueries.EmployeeExists(address.EmployeeId));

            if (!employeeExists)
            {
                return(StatusCode(StatusCodes.Status406NotAcceptable, new { message = "Employee not exists." }));
            }

            _address.Delete(new Address
            {
                EmployeeId = address.EmployeeId,
                Id         = address.AddressId
            });

            return(StatusCode(StatusCodes.Status200OK, new { message = "Address deleted successfully." }));
        }
Exemplo n.º 5
0
        public void Find_Employee_By_Id_01()
        {
            var result = employees.AsQueryable().Where(EmployeeQueries.EmployeeExists(new Guid()));

            Assert.Equal(1, result.Count());
        }