예제 #1
0
        public async Task <ActionResult <List <Release> > > Get()
        {
            List <Release> releases;

            try {
                logger.LogInformation("Trying to get releases from database");
                releases = await releasesService.GetAll();

                if (releases.Count == 0)
                {
                    string errorMessage = responseMessages.NotFound.Replace("$", "Lançamento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));
                }
            }
            catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action GET for /api/releases returns 200");
            return(Ok(releases));
        }
예제 #2
0
        public async Task <ActionResult <List <Statement> > > Get()
        {
            List <Statement> statements;

            try {
                logger.LogInformation("Trying to get associated releases from database");
                List <Release> releases = await releasesService.GetAll();

                if (releases.Count == 0)
                {
                    string errorMessage = responseMessages.NotFound.Replace("$", "Lançamento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));
                }

                var establishments = await establishmentService.GetAll();

                foreach (var release in releases)
                {
                    release.EstablishmentName = establishments.Find(e => e.Name == release.EstablishmentName).Type;
                }
                ;

                statements = releases.GroupBy(r => new { r.Date, r.EstablishmentName, r.PaymentMethod }).Select(x => {
                    var statement           = new Statement();
                    var curr                = x.First();
                    statement.Date          = curr.Date;
                    statement.PaymentMethod = curr.PaymentMethod;
                    statement.Type          = curr.EstablishmentName;
                    statement.TotalAmount   = x.Sum(xa => xa.Amount);
                    return(statement);
                }).ToList();
            }
            catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action GET for /api/statements returns 200");
            return(Ok(statements));
        }
예제 #3
0
        public async Task <ActionResult <List <Establishment> > > Get()
        {
            List <Establishment> establishments;

            try {
                logger.LogInformation("Trying to get establishments from database");
                establishments = await establishmentService.GetAll();

                if (establishments.Count == 0)
                {
                    string errorMessage = responseMessages.NotFound.Replace("$", "Estabelecimento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));
                }
            }
            catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action GET for /api/establishments returns 200");
            return(Ok(establishments));
        }