GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            var employee = InMemoryData.Employees.SingleOrDefault(x => x.No == request.No);

            if (employee != null)
            {
                var response = new EmployeeResponse
                {
                    Employee = employee
                };
                return(await Task.FromResult(response));
            }
            throw new Exception($"Employee not found with no:{request.No}");
        }
Beispiel #2
0
        public override Task <EmployeeResponse> GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            var employee = new Employee
            {
                Id        = 101,
                No        = request.No,
                FirstName = $"FirstName ${request.No}",
                LastName  = $"LastName ${request.No}",
            };
            var response = new EmployeeResponse {
                Employee = employee
            };

            return(Task.FromResult(response));
        }
        public override Task <EmployeeResponse> GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            try
            {
                //var trailer = new Metadata
                //{
                //    {"Filed","No"},
                //    {"Message","Something went wrong...."},
                //};
                //if (true)
                //{
                //    throw new RpcException(new Status(StatusCode.DataLoss,"Data is loss...."), trailer);

                //}

                var md = context.RequestHeaders;
                foreach (var pair in md)
                {
                    _logger.LogInformation($"{pair.Key}: {pair.Value}");
                }


                var employee = InMemoryData.Employees
                               .SingleOrDefault(x => x.No == request.No);
                if (employee != null)
                {
                    var response = new EmployeeResponse
                    {
                        Employee = employee
                    };

                    return(Task.FromResult(response));
                }
            }
            catch (RpcException re)
            {
                throw;
            }catch (Exception e)
            {
                _logger.LogError(e.Message);
                throw new RpcException(Status.DefaultCancelled, e.Message);
            }



            throw new Exception($"Employee not find with no: {request.No}");
        }
Beispiel #4
0
        public override Task <EmployeeResponse> GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            try
            {
                //if (true)
                //{
                //    var trailer = new Metadata
                //    {
                //        {"field", "No"},
                //        {"msg", "something went wrong ..."}
                //    };

                //    //throw new RpcException(status: Status.DefaultCancelled, "Server Error:");
                //    throw new RpcException(new Status(StatusCode.NotFound, "No is not found..."), trailer);
                //}

                var md = context.RequestHeaders;

                foreach (var item in md)
                {
                    _logger.LogInformation($"key:{item.Key} value:{item.Value}");
                }

                var employee = MemoryData.Employees.SingleOrDefault(r => r.No == request.No);

                if (employee != null)
                {
                    var response = new EmployeeResponse
                    {
                        Employee = employee
                    };

                    return(Task.FromResult(response));
                }
            }
            catch (RpcException re)
            {
                throw;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                throw new RpcException(status: Status.DefaultCancelled, e.Message);
            }

            throw new Exception($"employee has not found with no : {request.No}");
        }
        public async override Task <EmployeeResponse> GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            var md = context.RequestHeaders;

            foreach (var pair in md)
            {
                _logger.LogInformation($"{pair.Key}:{pair.Value}");
            }
            var employee = await _context.Employees.FirstOrDefaultAsync(e => e.No == request.No);

            if (employee != null)
            {
                var res = new EmployeeResponse
                {
                    Employee = _mapper.Map <Employee>(employee)
                };
                return(await Task.FromResult(res));
            }
            throw new Exception($"employee not found with no:{request.No}");
        }
        public override async Task <EmployeeResponse> GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            var metaData = context.RequestHeaders;

            foreach (var pair in metaData)
            {
                this.logger.LogInformation($"{pair.Key} : {pair.Value}");
            }

            var employee = InMemoryData.Employees.SingleOrDefault(employee => employee.No == request.No);

            if (employee != null)
            {
                return(new EmployeeResponse()
                {
                    Employee = employee
                });
            }

            throw new Exception("Employee Not Found.");
        }
        GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            var md = context.RequestHeaders;

            foreach (var pair in md)
            {
                _logger.LogInformation($"{pair.Key}:{pair.Value}");
            }
            var employee = InMemoryData.Employees
                           .SingleOrDefault(x => x.No == request.No);

            if (employee != null)
            {
                var response = new EmployeeResponse
                {
                    Employee = employee
                };
                return(Task.FromResult(response));
            }
            throw new Exception($"Employee not found with no : {request.No}");
        }
        public override Task <EmployeeResponse> GetByNo(GetByNoRequest request, ServerCallContext context)
        {
            //获取传入的元数据
            var md = context.RequestHeaders;

            foreach (var pair in md)
            {
                this.logger.LogInformation($"{pair.Key}:{pair.Value}");
            }
            var employee = DbData.Employees.FirstOrDefault(x => x.No == request.No);

            if (employee != null)
            {
                var response = new EmployeeResponse
                {
                    Employee = employee
                };
                return(Task.FromResult(response));
            }
            throw new Exception($"employee not found with no:{request.No} ");
        }