예제 #1
0
        public void TestDeleteEmployees()
        {
            onSetUp();
            var employeeBuilder = new EmployeeBuilder().setName(NAME);

            employeeRepository.AddEmployees(new List <Employee>()
            {
                employeeBuilder.CreateEmployee()
            });

            var removeEmployeeRequest = new RemoveEmployeeRequest()
            {
                Name = NAME
            };

            employeeController.Delete(removeEmployeeRequest);

            try
            {
                employeeController.Get(NAME);
                Assert.Fail("Expected exception to be thrown.");
            }
            catch (NoSuchEntityException e)
            {
                Assert.IsTrue(e.Message.Contains(NAME));
            }
        }
        public void Delete([FromBody] RemoveEmployeeRequest requestModel)
        {
            string name       = requestModel.Name;
            int    personalID = requestModel.PersonalID;

            if (name == null && personalID == 0)
            {
                throw new MalformedRequestException("Unable to parse name or personal ID from request parameters");
            }
            if (name == null)
            {
                try
                {
                    employeeRepository.RemoveEmployee(personalID);
                }
                catch (NoSuchEntityException)
                {
                    throw new NoSuchEntityException("No employee exists with ID: " + personalID);
                }
            }
            else
            {
                try
                {
                    employeeRepository.RemoveEmployee(name);
                }
                catch (NoSuchEntityException)
                {
                    throw new NoSuchEntityException("No employee exists with name: " + name);
                }
            }
        }
예제 #3
0
        public void TestDeleteEmployeeByID()
        {
            onSetUp();
            // Create an employee
            var employeeBuilder     = new EmployeeBuilder().setName(NAME);
            var addEmployeesRequest = employeeBuilder.CreateAddEmployeesRequest();

            // Add them to the database
            employeeController.Post(addEmployeesRequest);
            //Get them from the database and find their ID
            var databaseEmployee = employeeController.Get(NAME);
            var ID = databaseEmployee.Employees.Last().PersonalId;

            var removeEmployeeRequest = new RemoveEmployeeRequest()
            {
                PersonalID = ID
            };

            employeeController.Delete(removeEmployeeRequest);

            try
            {
                employeeController.GetEmployeeByID(ID);
                Assert.IsTrue(false); //Means that it found the employee so fail the test
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }
예제 #4
0
        public JsonResult Delete(System.Int32 id)
        {
            RemoveEmployeeRequest request = new RemoveEmployeeRequest();

            request.EmployeeID = id;
            RemoveEmployeeResponse response = _employeeService.RemoveEmployee(request);

            return(Json(response));
        }
예제 #5
0
        /// <summary>
        /// Remove
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task <RemoveEmployeeReply> Remove(RemoveEmployeeRequest request, ServerCallContext context)
        {
            CheckRequestInvalid(request);

            var result = new RemoveEmployeeReply();

            result.IsSuccess = _EmployeeBO.DeleteEntiy(new EmployeeDto {
                EmployeeID = request.EmployeeID
            });
            return(await Task.FromResult(result));
        }
예제 #6
0
        public RemoveEmployeeResponse RemoveEmployee(RemoveEmployeeRequest request)
        {
            RemoveEmployeeResponse response = new RemoveEmployeeResponse();

            response.Errors = new List <BusinessRule>();
            try {
                if (_employeeRepository.Remove(request.EmployeeID) > 0)
                {
                    response.EmployeeDeleted = true;
                }
            } catch (Exception ex)
            {
                response.Errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
            }
            return(response);
        }
예제 #7
0
        public void TestDeleteNonexistentEmployee()
        {
            OnSetUp();
            var removeEmployeeRequest = new RemoveEmployeeRequest {
                Name = Name
            };

            try
            {
                _employeeController.Delete(removeEmployeeRequest);
                Assert.Fail("Expected exception to be thrown.");
            }
            catch (NoSuchEntityException e)
            {
                Assert.IsTrue(e.Message.Contains(Name));
            }
        }
예제 #8
0
        public void Delete([FromBody] RemoveEmployeeRequest requestModel)
        {
            string name = requestModel.Name;

            if (name == null)
            {
                throw new MalformedRequestException("Unable to parse name from request parameters");
            }

            try
            {
                employeeRepository.RemoveEmployee(name);
            }
            catch (NoSuchEntityException)
            {
                throw new NoSuchEntityException("No employee exists with name: " + name);
            }
        }
        public void Delete([FromBody] RemoveEmployeeRequest requestModel)
        {
            int Id = requestModel.EmployeeId;

            if (Id == 0)
            {
                throw new MalformedRequestException("Unable to parse id from request parameters");
            }

            try
            {
                _employeeRepository.RemoveEmployee(Id);
            }
            catch (NoSuchEntityException)
            {
                throw new NoSuchEntityException("No employee exists with Id: " + Id);
            }
        }
        public async Task <ActionResult> RemoveEmployee(Guid serviceRequestId, [FromBody] RemoveEmployeeRequest dto)
        {
            await _serviceRequestService.RemoveEmployee(serviceRequestId, dto);

            return(NoContent());
        }