Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        private Order PreSave(Order model, SubscriptionsPlansViewModel plan)
        {
            model.CreditCard.CreditCardNumber = model.CreditCard.CreditCardNumber.Substring(12, 4);
            model.PurchaseDay     = DateTimeHelper.BrazilNow;
            model.PlanRenewalDate = model.PurchaseDay.AddMonths(plan.PlanMonths);

            var listHolidaysBrazil = Holidayshelper.GetHolidaysByCurrentYear().ToList();

            if (listHolidaysBrazil.Contains(model.PlanRenewalDate))
            {
                model.PlanRenewalDate = DateTimeHelper.diaUtil(model.PlanRenewalDate.AddDays(1));
            }


            model.Total = plan.Value;

            return(model);
        }