Example #1
0
        public async Task <ActionResult <Release> > Post([FromBody] ReleaseRequest body)
        {
            Release resultRelease;

            try {
                logger.LogInformation("Trying to get associated establishment");
                var establishment = await establishmentService.GetByName(body.EstablishmentName);

                if (establishment == null)
                {
                    string errorMessage = responseMessages.CantFoundGivenName.Replace("$", "estabelecimento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));
                }

                logger.LogInformation("Inserting release into database");
                var newRelease = new Release()
                {
                    Date              = body.Date,
                    PaymentMethod     = body.PaymentMethod,
                    Amount            = body.Amount,
                    EstablishmentName = establishment.Name,
                    CreatedAt         = DateTime.Now
                };

                resultRelease = await releasesService.CreateItem(newRelease);
            } catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action POST for /api/releases returns 201");
            return(Created("", resultRelease));
        }
Example #2
0
        public async Task <ActionResult <Establishment> > Post([FromBody] EstablishmentRequest body)
        {
            Establishment resultEstablishment;

            try {
                logger.LogInformation("Trying to verify if establishment with given Name exists");
                var establishment = await establishmentService.GetByName(body.Name.FirstCharToUpper());

                if (establishment != null)
                {
                    string errorMessage = responseMessages.NotAccepted.Replace("$", "estabelecimento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 406));
                }

                logger.LogInformation("Inserting establishment into database");
                var newEstablishment = new Establishment()
                {
                    Name      = body.Name.FirstCharToUpper(),
                    Type      = body.Type.FirstCharToUpper(),
                    CreatedAt = DateTime.Now
                };

                resultEstablishment = await establishmentService.CreateItem(newEstablishment);
            } catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action POST for /api/establishments returns 201");
            return(Created("", resultEstablishment));
        }