Esempio n. 1
0
 public async Task <OrderRepoResponse> GetOrder(int orderId)
 {
     validateOrderId(orderId);
     _dataLogger.LogInformation("Input data", orderId);
     try
     {
         return(await GetOrderData(orderId));
     }
     catch (Exception ex)
     {
         _dataLogger.LogError(ex);
         throw;
     }
 }
Esempio n. 2
0
 public async Task <List <ClientOrderRepoResponseModel> > GetClientOrders(int clientId)
 {
     validateGetClientOrders(clientId);
     _dataLogger.LogInformation("Input data", clientId);
     try
     {
         return(await GetClientOrdersSqlResults(clientId));
     }
     catch (Exception ex)
     {
         _dataLogger.LogError(ex);
         throw;
     }
 }
Esempio n. 3
0
        public async Task <List <ClientOrderApplicationResponseModel> > GetClientOrders(int clientId)
        {
            _dataLogger.LogInformation("Application.UseCases.GetClientOrders.GetClientOrders(clientId)", clientId);

            var repoClientOrders = await _clientOrders.GetClientOrders(clientId);

            return(_mapper.Map <List <ClientOrderApplicationResponseModel> >(repoClientOrders));
        }
Esempio n. 4
0
        public async Task <List <CustomerSearchApplicationResponseModel> > GetCustomersByName(string name)
        {
            _dataLogger.LogInformation("Application.UseCases.SearchCustomerByName.GetCustomersByName(name)", name);

            var customers = await _customerSearchRepo.SearchCustomers(name);

            return(_mapper.Map <List <CustomerSearchApplicationResponseModel> >(customers));
        }
Esempio n. 5
0
        public async Task <OrderApplicationResponseModel> GetOrder(int clientId, int orderId)
        {
            _dataLogger.LogInformation("Application.UseCases.Order.GetOrder(clientId, orderId)", clientId, orderId);

            var repoOrder = await _orderRepo.GetOrder(orderId);

            var order = _mapper.Map <OrderApplicationResponseModel>(repoOrder);

            _clientOrderAuthorization.AuthorizeClientToViewOrder(clientId, order);

            return(order);
        }
        public async Task <ActionResult <IEnumerable <CustomerSearchMvcResponseModel> > > Index()
        {
            _dataLogger.LogInformation("In WebUi.Controllers.CustomerSearchControllerIndex()");

            try
            {
                return(View(await GetCustomers(string.Empty)));
            }
            catch (Exception ex)
            {
                _dataLogger.LogError(ex);
                return(BadRequest(base.GetResponseObject(Constants.ERROR_RESPONSE, Constants.ERROR_RESPONSE)));
            }
        }
        // Middleware: Custom middleware needs an Invoke method that is called when requests come in for processing.
        //             It should have an HttpContext as its first argument and, optionally, other services that are
        //             needed from DI. Dependencies which are injected at this level will be scoped to the lifetime of the request.
        public async Task Invoke(HttpContext context, IDataLogger dataLogger)
        {
            try
            {
                //First, get the incoming request
                var request = await FormatRequest(context.Request);

                dataLogger.LogInformation("Request", request);
                dataLogger.LogInformation("RequestHeader", FormatHeaders(context.Request));

                //Copy a pointer to the original response body stream
                var originalBodyStream = context.Response.Body;

                //Create a new memory stream...
                using (var responseBody = new MemoryStream())
                {
                    //...and use that for the temporary response body
                    context.Response.Body = responseBody;

                    //Continue down the Middleware pipeline, eventually returning to this class
                    await _next(context);

                    //Format the response from the server
                    var response = await FormatResponse(context.Response);

                    dataLogger.LogInformation("Response", response);
                    //Copy the contents of the new memory stream (which contains the response) to the original stream, which is then returned to the client.
                    await responseBody.CopyToAsync(originalBodyStream);
                }
            }
            catch (Exception)
            {
                // Do nothing. We don't want to stop execution.
                await _next(context);
            }
        }