Exemplo n.º 1
0
        public List <Firm> GetAllFirms(string transactionID)
        {
            List <Firm>        firmsList          = new List <Firm>();
            FinancingPMSLogger financingPMSLogger = new FinancingPMSLogger("GetAllFirms service (DB call) has started", transactionID);
            SqlDataReader      reader             = null;

            _logger.LogInformation(message: financingPMSLogger.ToString());
            try
            {
                using (_logger.BeginScope("GetAllFirms"))
                    using (SqlCommand sqlCommand = new SqlCommand())
                    {
                        sqlCommand.Connection  = _connection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = GETALLFIRMS_SP;

                        if (_connection.State == ConnectionState.Closed)
                        {
                            _connection.Open();
                        }

                        using (reader = sqlCommand.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    Firm firm = new Firm()
                                    {
                                        Id   = reader["Id"].ToString(),
                                        Name = reader["Name"].ToString()
                                    };
                                    firmsList.Add(firm);
                                }
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                financingPMSLogger.message = "Error occured while getting Firms list from database";
                _logger.LogError(exception: ex, message: financingPMSLogger.ToString());
                throw ex;
            }
            finally
            {
                _connection.Close();
            }
            financingPMSLogger.message = "GetAllFirms service (DB call) has ended";
            _logger.LogInformation(message: financingPMSLogger.ToString());
            return(firmsList);
        }
        public async Task Invoke(HttpContext context)
        {
            Stopwatch time = new Stopwatch();

            time.Start();
            Guid transactionID = Guid.NewGuid();

            context.Request.Headers.Add("transactionID", transactionID.ToString());

            FinancingPMSLogger logMessage = new FinancingPMSLogger
            {
                message       = $"Started executing the Http Request at {time.Elapsed}",
                transactionID = transactionID.ToString()
            };

            _logger.LogInformation(message: logMessage.ToString());
            await _next.Invoke(context);

            time.Stop();

            logMessage.message = $"Completed executing the Http Request at {time.Elapsed}";
        }
Exemplo n.º 3
0
        public IActionResult GetAllFirms()
        {
            Guid transactionID            = Guid.NewGuid();
            FinancingPMSLogger logMessage = new FinancingPMSLogger("GetAllFirms execution started", transactionID.ToString());

            _logger.LogInformation(message: logMessage.ToString());
            List <Firm> firmsList = new List <Firm>();

            try
            {
                firmsList = _firmService.GetAllFirms(transactionID.ToString());
                if (firmsList.Count == 0)
                {
                    return(StatusCode(204));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            logMessage.message = "GetAllFirms execution ended";
            _logger.LogInformation(message: logMessage.ToString());
            return(Ok(firmsList));
        }