Ejemplo n.º 1
0
        public async Task <IActionResult> GetOrders()
        {
            try
            {
                var companies = await _orderService.AllAsync();

                return(Ok(companies));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task RunDaily()
        {
            try
            {
                var ordersExpiring = await _ordersService.AllAsync(x => x.PlanRenewalDate.Date == DateTimeHelper.BrazilNow.Date);

                if (ordersExpiring.Any())
                {
                    foreach (var order in ordersExpiring)
                    {
                        _logger.LogWarning($"Renovando a assinatura com id: {order.Id}, do usuario: {order.UserId}, com o plano {order.SubscriptionPlanId}");

                        var subscriptionPlan = await _subscriptionPlansService.GetAsync(order.SubscriptionPlanId);

                        var renewalFutureDate =
                            DateTimeHelper.BrazilNow.AddMonths(subscriptionPlan.PlanMonths).AddDays(1);

                        var listHolidaysBrazil = Holidayshelper.GetHolidaysByCurrentYear().ToList();
                        if (listHolidaysBrazil.Contains(renewalFutureDate))
                        {
                            renewalFutureDate = DateTimeHelper.diaUtil(renewalFutureDate.AddDays(1));
                        }

                        var newOrder = new Order
                        {
                            CreditCardId       = order.CreditCardId,
                            SubscriptionPlanId = order.SubscriptionPlanId,
                            PurchaseDay        = DateTimeHelper.BrazilNow,
                            PlanRenewalDate    = renewalFutureDate,
                            Total  = subscriptionPlan.Value,
                            UserId = order.UserId
                        };


                        var result = await _ordersService.InsertModelAsync(newOrder);

                        _logger.LogWarning($"Assinatura com id: {result.Id}, do usuario: {result.UserId}, com o plano {result.SubscriptionPlanId}. Foi renovada com sucesso!");
                        Console.WriteLine(result + "/r");
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogWarning($"Não foi possivel renovar a assinatura, erro {e.Message}");

                Console.WriteLine(e.Message);
            }
        }