Ejemplo n.º 1
0
 public Task<GetAllCustomerResponse> getAllCustomer(SearchCustomerRequest request)
 {
     GetAllCustomerResponse response = new GetAllCustomerResponse();
     try
     {
         CustomerModel customerModel = new CustomerModel();
         customerModel.Name = request.Name;
         customerModel.Code = request.Code;
         customerModel.PhoneNumber = request.PhoneNumber;
         PagedModel model = _service.Search(customerModel, request.Page, request.PageSize);
         response.Data = (IEnumerable<CustomerModel>) model.Data;
         if (response.Data!=null)
         {
             foreach (CustomerModel customer in response.Data)
             {
                 customer.Address = _addressService.Get(customer.AddressId);
             }
         }
         response.Status = new StatusResponse("OK", true);
         response.Total = model.PageTotal;
         response.Page = request.Page;
         response.PageSize = request.PageSize;
     }
     catch(Exception e)
     {
         response.Status = new StatusResponse(e.ToString(), false);
     }
     return Task.FromResult(response);
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetByToken()
        {
            var accesToken = Request.Headers["Authorization"];
            var handler    = new JwtSecurityTokenHandler();
            var jsonToken  = handler.ReadToken(accesToken) as JwtSecurityToken;
            var id         = Int32.Parse(jsonToken.Claims.First().Value);
            var result     = await _CustomerAppService.getCustomerById(id);

            List <CustomerModel> lst = new List <CustomerModel>();

            lst.Add(result.Data);
            GetAllCustomerResponse customerResponse = new GetAllCustomerResponse()
            {
                Status = result.Status,
                Total  = 1,
                Data   = lst
            };

            return(Ok(customerResponse));
        }
Ejemplo n.º 3
0
        public GetAllCustomerResponse GetAllCustomers()
        {
            GetAllCustomerResponse response = new GetAllCustomerResponse();

            IEnumerable <Customer> customers = _customerRepository
                                               .FindAll();

            if (customers != null)
            {
                response.CustomerFound = true;
                response.Customers     = customers.ConvertToCustomerViews();
            }
            else
            {
                response.CustomerFound = false;
            }


            return(response);
        }