Exemplo n.º 1
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public async System.Threading.Tasks.Task ExecuteAsync()
        {
            var rateRemainderCustomers = await _customerService.GetAllPushNotificationCustomersAsync(isRateReminderNotification : true);

            if (rateRemainderCustomers.Count > 0)
            {
                //DateTime currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                var osIds = new List <int> {
                    (int)OrderStatus.Complete, (int)OrderStatus.Pending, (int)OrderStatus.Processing
                };
                foreach (var rateRemainderCustomer in rateRemainderCustomers)
                {
                    var customerOrders = await _orderService.SearchOrdersAsync(customerId : rateRemainderCustomer.Id, osIds : osIds, sendRateNotification : true); //createdToUtc: currentDate,

                    if (customerOrders.Count > 0)
                    {
                        foreach (var customerOrder in customerOrders)
                        {
                            TimeSpan diff = DateTime.Now.Subtract(customerOrder.ScheduleDate);
                            if (diff.Hours >= 1)
                            {
                                if (!string.IsNullOrEmpty(rateRemainderCustomer.PushToken))
                                {
                                    var expoSDKClient = new PushApiTaskClient();
                                    var pushTicketReq = new PushApiTaskTicketRequest()
                                    {
                                        PushTo = new List <string>()
                                        {
                                            rateRemainderCustomer.PushToken
                                        },
                                        PushTitle = await _localizationService.GetResourceAsync("RateRemainderNotificationTask.Title"),
                                        PushBody  = await _localizationService.GetResourceAsync("RateRemainderNotificationTask.Body"),
                                        PushData  = new { customerOrder.Id }
                                    };
                                    var result = await expoSDKClient.PushSendAsync(pushTicketReq);

                                    customerOrder.RateNotificationSend = true;
                                    await _orderService.UpdateOrderAsync(customerOrder);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public async System.Threading.Tasks.Task ExecuteAsync()
        {
            var startingHour = await _settingService.GetSettingByKeyAsync <int>("catalogSettings.StartingTimeOfRemindMeTask");

            if (startingHour == 0)
            {
                startingHour = 11;
            }

            var customers = await _customerService.GetAllPushNotificationCustomersAsync(isRemindMeNotification : true);

            if (customers.Count > 0)
            {
                DateTime currentDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day);
                var      osIds       = new List <int> {
                    (int)OrderStatus.Complete, (int)OrderStatus.Pending, (int)OrderStatus.Processing
                };
                foreach (var customer in customers)
                {
                    var customerTime = _dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, TimeZoneInfo.Utc, await _dateTimeHelper.GetCustomerTimeZoneAsync(customer));
                    if (customerTime.Hour == startingHour)
                    {
                        var order = await _orderService.SearchOrdersAsync(customerId : customer.Id, createdToUtc : currentDate, osIds : osIds);

                        if (order.Count == 0)
                        {
                            if (!string.IsNullOrEmpty(customer.PushToken))
                            {
                                var expoSDKClient = new PushApiTaskClient();
                                var pushTicketReq = new PushApiTaskTicketRequest()
                                {
                                    PushTo = new List <string>()
                                    {
                                        customer.PushToken
                                    },
                                    PushTitle = await _localizationService.GetResourceAsync("RemindMeNotificationTask.Title"),
                                    PushBody  = await _localizationService.GetResourceAsync("RemindMeNotificationTask.Body")
                                };
                                var result = await expoSDKClient.PushSendAsync(pushTicketReq);
                            }
                        }
                    }
                }
            }
        }