< Summary

Information
Class: Services.DataServices.OrderArchiveDataService
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/DataServices/OrderArchiveDataService.cs
Line coverage
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 98
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ArchiveOrderAsync()100%22100%
GetArchivedOrdersAsync()100%11100%
RestoreFromArchiveAsync()100%22100%
IsOrderArchivedAsync()100%11100%
AddOrderArchive()100%11100%
DeleteOrderArchive()100%11100%
GetOrderArchives()100%11100%
GetOrderArchiveAsync()100%11100%
GetOrderArchiveAsync()100%11100%
UpdateOrderArchive()100%11100%
SaveChanges()100%11100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/DataServices/OrderArchiveDataService.cs

#LineLine coverage
 1using OzonDomains.Models;
 2using OzonRepositories.Data;
 3
 4namespace Services.DataServices
 5{
 6    public class OrderArchiveDataService : IDataServices
 7    {
 8        private readonly OrderArchiveRepository _repository;
 9
 1510        public OrderArchiveDataService(OrderArchiveRepository repository)
 11        {
 1512            _repository = repository;
 1513        }
 14
 15        // Архивировать заказ
 16        public async Task<int> ArchiveOrderAsync(int orderId, string archivedBy = "System", string? reason = null)
 17        {
 18            // Проверяем, не архивирован ли уже заказ
 619            var existingArchive = await _repository.GetByOrderIdAsync(orderId);
 620            if (existingArchive != null)
 21            {
 122                throw new InvalidOperationException($"Заказ с ID {orderId} уже архивирован");
 23            }
 24
 525            var archiveRecord = new OrderArchive
 526            {
 527                OrderId = orderId,
 528                ArchivedBy = archivedBy,
 529                ArchiveReason = reason,
 530                ArchivedAt = DateTime.Now
 531            };
 32
 533            return await _repository.Add(archiveRecord);
 534        }
 35
 36        // Получить архивированные заказы с деталями
 37        public async Task<List<Order>> GetArchivedOrdersAsync()
 38        {
 239            var archivedRecords = await _repository.GetArchivedOrdersWithDetailsAsync();
 540            return archivedRecords.Select(ar => ar.Order).ToList();
 241        }
 42
 43        // Восстановить из архива
 44        public async Task<int> RestoreFromArchiveAsync(int orderId)
 45        {
 246            var archiveRecord = await _repository.GetByOrderIdAsync(orderId);
 47
 248            if (archiveRecord == null)
 49            {
 150                throw new InvalidOperationException($"Архивная запись для заказа с ID {orderId} не найдена");
 51            }
 52
 153            return await _repository.Delete(archiveRecord);
 154        }
 55
 56        // Проверить, архивирован ли заказ
 57        public async Task<bool> IsOrderArchivedAsync(int orderId)
 58        {
 559            return await _repository.IsOrderArchivedAsync(orderId);
 560        }
 61
 62        // Базовые CRUD методы (если нужны)
 63        public async Task<int> AddOrderArchive(OrderArchive value)
 64        {
 165            return await _repository.Add(value);
 166        }
 67
 68        public async Task<int> DeleteOrderArchive(OrderArchive value)
 69        {
 170            return await _repository.Delete(value);
 171        }
 72
 73        public async Task<List<OrderArchive>> GetOrderArchives()
 74        {
 175            return await _repository.Get();
 176        }
 77
 78        public async Task<OrderArchive?> GetOrderArchiveAsync(int id)
 79        {
 280            return await _repository.GetAsync(id);
 281        }
 82
 83        public async Task<OrderArchive?> GetOrderArchiveAsync(OrderArchive value)
 84        {
 285            return await _repository.GetAsync(value);
 286        }
 87
 88        public async Task<int> UpdateOrderArchive(OrderArchive value)
 89        {
 190            return await _repository.Update(value);
 191        }
 92
 93        public async Task<int> SaveChanges()
 94        {
 195            return await _repository.SaveChanges();
 196        }
 97    }
 98}