public FastDeliveryAvailabilityHistoryJournalViewModel(FastDeliveryAvailabilityFilterViewModel filterViewModel, IUnitOfWorkFactory unitOfWorkFactory, ICommonServices commonServices, IEmployeeService employeeService, IFileDialogService fileDialogService, IFastDeliveryAvailabilityHistoryParameterProvider fastDeliveryAvailabilityHistoryParameterProvider) : base(filterViewModel, unitOfWorkFactory, commonServices) { _employeeService = employeeService ?? throw new ArgumentNullException(nameof(employeeService)); _fileDialogService = fileDialogService ?? throw new ArgumentNullException(nameof(fileDialogService)); var availabilityHistoryParameterProvider = fastDeliveryAvailabilityHistoryParameterProvider ?? throw new ArgumentNullException(nameof(fastDeliveryAvailabilityHistoryParameterProvider)); TabName = "Журнал истории проверок экспресс-доставок"; UpdateOnChanges( typeof(FastDeliveryAvailabilityHistory), typeof(FastDeliveryAvailabilityHistoryItem), typeof(FastDeliveryNomenclatureDistributionHistory), typeof(FastDeliveryOrderItemHistory) ); var fastDeliveryAvailabilityHistoryModel = new FastDeliveryAvailabilityHistoryModel(unitOfWorkFactory); fastDeliveryAvailabilityHistoryModel.ClearFastDeliveryAvailabilityHistory(availabilityHistoryParameterProvider); _timer = new Timer(_interval); _timer.Elapsed += TimerOnElapsed; _timer.Start(); }
public void ClearFastDeliveryAvailabilityHistory(IFastDeliveryAvailabilityHistoryParameterProvider fastDeliveryAvailabilityHistoryParameterProvider) { if (fastDeliveryAvailabilityHistoryParameterProvider.FastDeliveryHistoryClearDate >= DateTime.Now.Date) { return; } using (var uow = _unitOfWorkFactory.CreateWithoutRoot("ClearFastDeliveryAvailabilityHistory")) { var availabilityHistories = uow.Session.Query <FastDeliveryAvailabilityHistory>() .Where(x => x.VerificationDate < DateTime.Now.Date.AddDays(-fastDeliveryAvailabilityHistoryParameterProvider.FastDeliveryHistoryStorageDays)) .ToList(); try { foreach (var history in availabilityHistories) { uow.Delete(history); } uow.Commit(); } catch (Exception e) { _logger.Error(e, "Не удалось очистить журнал истории проверки экспресс-доставки."); } } fastDeliveryAvailabilityHistoryParameterProvider.UpdateFastDeliveryHistoryClearDate(DateTime.Now.Date.ToString()); }