public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken) { if (request.Employee == null || request.Employee.CollectionId == 0 || request.Employee.EmployeeId == 0) { throw new BusinessException("AddWrongInformation"); } var checkEmployee = (await collectionEmployeeQueries.Gets($"collection_id = {request.Employee.CollectionId} and employee_id = {request.Employee.EmployeeId}")).FirstOrDefault(); if (checkEmployee != null) { throw new BusinessException("Employee.NotExisted"); } return(await collectionEmployeeRepository.Add(request.Employee) > 0 ? 0 : throw new BusinessException("Common.AddFail")); }
public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken) { if (request.Employee == null || request.Employee.Id == 0 || request.Employee.EmployeeId == 0) { throw new BusinessException("AddWrongInformation"); } var collectionEmployee = (await collectionEmployeeQueries.Gets($"id = {request.Employee.Id}")).FirstOrDefault(); if (collectionEmployee != null) { collectionEmployee.EmployeeId = request.Employee.EmployeeId; var rs = await collectionEmployeeRepository.Update(collectionEmployee); return(rs == 0 ? 0 : throw new BusinessException("Common.UpdateFail")); } // CollectionEmployee isn't exsited. Of course, we don't need update it. return(0); }