Beispiel #1
0
        public GetCustomerListResponse Search([FromBody] GetCustomerListRequest request)
        {
            const string message = "Could not find customer.";

            try
            {
                var response = new GetCustomerListResponse();

                using (var db = new EntityDb()) {
                    var customerList = db.Customers.AsQueryable();

                    // This is the two lines needed from the Expression Builder project
                    // to build the Lambda query.
                    var search = new SearchFilter <Customer>();
                    Filter <Customer> filter = search.Filter(request.SearchCriteria);

                    var results = customerList.Where(filter)
                                  .Select(c => new CustomerDto
                    {
                        CustomerId           = c.CustomerID,
                        CustomerName         = c.CustomerName,
                        PhoneNumber          = c.PhoneNumber,
                        DeliveryAddressLine1 = c.DeliveryAddressLine1,
                        DeliveryAddressLine2 = c.DeliveryAddressLine2,
                        DeliveryPostalCode   = c.DeliveryPostalCode,
                        PostalAddressLine1   = c.PostalAddressLine1,
                        PostalAddressLine2   = c.PostalAddressLine2
                    }).ToList();

                    response.CustomerList = results;
                }

                response.Success = true;
                return(response);
            }
            catch (Exception)
            {
                return(new GetCustomerListResponse {
                    Success = false, Message = message
                });
            }
        }
        public static GetCustomerListResponse Unmarshall(UnmarshallerContext _ctx)
        {
            GetCustomerListResponse getCustomerListResponse = new GetCustomerListResponse();

            getCustomerListResponse.HttpResponse = _ctx.HttpResponse;
            getCustomerListResponse.RequestId    = _ctx.StringValue("GetCustomerList.RequestId");
            getCustomerListResponse.Success      = _ctx.BooleanValue("GetCustomerList.Success");
            getCustomerListResponse.Code         = _ctx.StringValue("GetCustomerList.Code");
            getCustomerListResponse.Message      = _ctx.StringValue("GetCustomerList.Message");

            GetCustomerListResponse.GetCustomerList_Data data = new GetCustomerListResponse.GetCustomerList_Data();

            List <string> data_uidList = new List <string>();

            for (int i = 0; i < _ctx.Length("GetCustomerList.Data.UidList.Length"); i++)
            {
                data_uidList.Add(_ctx.StringValue("GetCustomerList.Data.UidList[" + i + "]"));
            }
            data.UidList = data_uidList;
            getCustomerListResponse.Data = data;

            return(getCustomerListResponse);
        }