Пример #1
0
        public async Task InsertCronTaskAsync(int scheduleTaskId, string cronExpression)
        {
            var ga = _genericAttributeRepository.Table
                     .FirstOrDefault(gar => gar.KeyGroup == nameof(ScheduleTask) && gar.Key == CronTasksDefaults.CronExpressionGenericAttributeKey && gar.EntityId == scheduleTaskId);

            if (ga == null)
            {
                ga = new GenericAttribute()
                {
                    StoreId  = 0,
                    KeyGroup = nameof(ScheduleTask),
                    Key      = CronTasksDefaults.CronExpressionGenericAttributeKey,
                    EntityId = scheduleTaskId,
                    Value    = cronExpression
                };
                await _genericAttributeService.InsertAttributeAsync(ga);
            }
            else
            {
                ga.Value = cronExpression;
                await _genericAttributeService.UpdateAttributeAsync(ga);
            }

            var scheduledTask = await _scheduleTaskService.GetTaskByIdAsync(scheduleTaskId);

            if (scheduledTask != null)
            {
                scheduledTask.Enabled = false;
                await _scheduleTaskService.UpdateTaskAsync(scheduledTask);
            }

            await RescheduleQuartzJobAsync(scheduleTaskId, cronExpression);
        }
Пример #2
0
        public async Task ShouldSetCreatedOrUpdatedDateUtcInInsertAttribute()
        {
            var attribute = new global::Nop.Core.Domain.Common.GenericAttribute
            {
                Key = "test", KeyGroup = "test", Value = "test", CreatedOrUpdatedDateUTC = null
            };

            await _genericAttributeService.InsertAttributeAsync(attribute);

            var createdOrUpdatedDate = attribute.CreatedOrUpdatedDateUTC;

            await _genericAttributeService.DeleteAttributeAsync(attribute);

            Assert.That(createdOrUpdatedDate,
                        Is.EqualTo(DateTime.UtcNow).Within(1).Minutes);
        }