コード例 #1
0
        public async Task <int> GetPercentualCashback(double valorCompra, string usuario)
        {
            try
            {
                List <RegraCashback> regras = (await regraService.GetAll(usuario)).ToList();

                int percentual = 0;

                foreach (var item in regras)
                {
                    if (!item.Fim.Equals(0))
                    {
                        if (valorCompra >= item.Inicio && valorCompra < item.Fim)
                        {
                            percentual = item.Percentual;
                        }
                    }
                    else
                    {
                        if (valorCompra >= item.Inicio)
                        {
                            percentual = item.Percentual;
                        }
                    }
                }

                return(percentual);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
コード例 #2
0
        public async Task <ActionResult <IEnumerable <RegraCashback> > > GetAll()
        {
            const string endpointName = nameof(GetAll);
            string       header       = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}";

            try
            {
                logger.LogInformation((int)LogEventEnum.Events.GetItem,
                                      $"{header} - {MessageLog.Start.Value}");

                IEnumerable <RegraCashback> entities = await service.GetAll(UserTokenOptions.GetClaimTypesNameValue(User.Identity));

                if (entities.ToList().Count <= 0)
                {
                    logger.LogInformation((int)LogEventEnum.Events.GetItemNotFound,
                                          $"{header} - {MessageError.NotFound.Value}");

                    return(NotFound(new { message = MessageError.NotFound.Value }));
                }

                logger.LogInformation((int)LogEventEnum.Events.GetItem,
                                      $"{header} - {MessageLog.Stop.Value}");

                return(Ok(entities));
            }
            catch (Exception ex)
            {
                logger.LogError((int)LogEventEnum.Events.GetItemError, ex,
                                $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}");

                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  new { message = MessageError.InternalError.Value, error = ex.Message }));
            }
        }