/// <summary> /// Выставляет родителей для агрегата /// </summary> /// <param name="component"></param> /// <returns></returns> public void SetDestinations(General.Accessory.Component component) { TransferRecord lastTransfer = component.TransferRecords.GetLast(); if (lastTransfer == null) { return; } //throw new Exception($"1513: Component {component.ItemId} has no transfer records"); // if (lastTransfer.DestinationObjectType == SmartCoreType.Store) { var store = _casEnvironment.Stores.GetItemById(lastTransfer.DestinationObjectId); if (store == null) { // перемещение вникуда ! throw new Exception($"1552: Destination object ID:{lastTransfer.DestinationObjectId} was not found"); } component.ParentStoreId = store.ItemId; } else if (lastTransfer.DestinationObjectType == SmartCoreType.Operator) { var op = _casEnvironment.Operators.GetItemById(lastTransfer.DestinationObjectId); if (op == null) { // перемещение вникуда ! throw new Exception($"1552: Destination object ID:{lastTransfer.DestinationObjectId} was not found"); } component.ParentOperator = op; } else if (lastTransfer.DestinationObjectType == SmartCoreType.BaseComponent) { var baseComponent = _casEnvironment.BaseComponents.GetItemById(lastTransfer.DestinationObjectId); //TODO(Evgenii Babak): использовать ComponentCore if (baseComponent != null) { component.ParentBaseComponent = baseComponent; if (baseComponent.LastDestinationObjectType == SmartCoreType.Aircraft) { component.ParentAircraftId = baseComponent.LastDestinationObjectId; } else if (baseComponent.LastDestinationObjectType == SmartCoreType.Store) { component.ParentStoreId = baseComponent.LastDestinationObjectId; } } } else if (lastTransfer.DestinationObjectType == SmartCoreType.Aircraft) { component.ParentAircraftId = lastTransfer.DestinationObjectId; } else if (lastTransfer.DestinationObjectType == SmartCoreType.Supplier) { component.ParentSupplierId = lastTransfer.DestinationObjectId; } else if (lastTransfer.DestinationObjectType == SmartCoreType.Employee) { component.ParentSpecialistId = lastTransfer.DestinationObjectId; } if (component.ParentStoreId <= 0 && component.ParentAircraftId <= 0 && component.ParentSupplierId <= 0 && component.ParentSpecialistId <= 0 && component.ParentOperator == null) { throw new Exception("1453: Failed to specify parent object to detail"); } }
/// <summary> /// Добавить выполнение работы к задаче /// </summary> /// <param name="performance"></param> /// <param name="saveAttachedFile"></param> public void Save(AbstractPerformanceRecord performance, bool saveAttachedFile = true) { if (performance == null) { return; } var type = AuditOperation.Created; if (performance.ItemId > 0) { type = AuditOperation.Changed; } performance.CorrectorId = _casEnvironment.IdentityUser.ItemId; _casEnvironment.Keeper.Save(performance, saveAttachedFile); _auditRepository.WriteAsync(performance, type, _casEnvironment.IdentityUser); if (performance.Parent.PerformanceRecords.GetItemById(performance.ItemId) == null) { performance.Parent.PerformanceRecords.Add(performance); } if (performance.Parent is MaintenanceDirective) { DirectiveRecord ddr = _casEnvironment.NewLoader.GetObjectListAll <DirectiveRecordDTO, DirectiveRecord>(new Filter("MaintenanceDirectiveRecordId", performance.ItemId)).FirstOrDefault(); if (ddr != null) { ComponentDirective dd = _casEnvironment.NewLoader.GetObject <ComponentDirectiveDTO, ComponentDirective>(new Filter("ItemId", ddr.ParentId)); if (dd != null) { BaseComponent bd = _componentCore.GetBaseComponentById(dd.ComponentId); if (bd != null) { ddr.OnLifelength = _casEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(bd, performance.RecordDate); } else { General.Accessory.Component d = _componentCore.GetComponentById(dd.ComponentId); if (d != null) { ddr.OnLifelength = _casEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(d, performance.RecordDate); } } } ddr.RecordDate = performance.RecordDate; _casEnvironment.NewKeeper.Save(ddr, saveAttachedFile); } } else if (performance.Parent is ComponentDirective) { DirectiveRecord ddr = performance as DirectiveRecord; if (ddr != null) { DirectiveRecord mpdRecord = _casEnvironment.NewLoader.GetObject <DirectiveRecordDTO, DirectiveRecord>(new Filter("ItemId", ddr.MaintenanceDirectiveRecordId)); if (mpdRecord != null) { MaintenanceDirective md = _maintenanceCore.GetMaintenanceDirective(mpdRecord.ParentId); if (md != null) { mpdRecord.OnLifelength = _casEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(md.ParentBaseComponent, ddr.RecordDate); } mpdRecord.RecordDate = ddr.RecordDate; _casEnvironment.NewKeeper.Save(mpdRecord, saveAttachedFile); } } } }