/* * Глобальные коллекции */ #region public void Save(BaseSmartCoreObject saveObject) public void Save(BaseEntityObject saveObject) { if (saveObject == null) { return; } saveObject.CorrectorId = _casEnvironment.IdentityUser.ItemId; var type = AuditOperation.Created; if (saveObject.ItemId > 0) { type = AuditOperation.Changed; } CasEnvironment.Keeper.Save(saveObject); _auditRepository.WriteAsync(saveObject, type, _casEnvironment.IdentityUser); if (saveObject is AbstractDictionary) { IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType()); if (col == null) { return; } AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId); if (dict == null || saveObject.ItemId != dict.ItemId) { col.Add(saveObject); } else { dict.SetProperties((AbstractDictionary)saveObject); } } if (saveObject is Store) { Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.Stores.Add((Store)saveObject); } } if (saveObject is BaseComponent) { BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.BaseComponents.Add((BaseComponent)saveObject); } } }
/// <summary> /// Возвращает все записи о перемешении агрегатов на переданное ВС /// </summary> /// <returns></returns> public IEnumerable <TransferRecord> GetTransferRecordsFromAndTo(Aircraft aircraft, Store s) { if (aircraft == null && s == null) { return(null); } string baseStatement = ""; var collection = new List <TransferRecord>(); if (aircraft != null) { var parentIds = _newLoader.GetSelectColumnOnly <TransferRecordDTO>(new List <Filter>() { new Filter("DestinationObjectID", aircraft.ItemId), new Filter("DestinationObjectType", aircraft.SmartCoreObjectType.ItemId), }, "ParentID"); collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>() { new Filter("FromAircraftID", aircraft.ItemId), new Filter("FromStoreID", 0), }, true).OrderByDescending(t => t.TransferDate)); collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>() { new Filter("DestinationObjectID", aircraft.ItemId), new Filter("DestinationObjectType", aircraft.SmartCoreObjectType.ItemId), }, true).OrderByDescending(t => t.TransferDate)); if (parentIds != null) { collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("DestinationObjectID", parentIds), true).OrderByDescending(t => t.TransferDate)); } } else { var parentIds = _newLoader.GetSelectColumnOnly <TransferRecordDTO>(new List <Filter>() { new Filter("DestinationObjectID", s.ItemId), new Filter("DestinationObjectType", s.SmartCoreObjectType.ItemId), }, "ParentID"); collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("FromStoreID", s.ItemId), true).OrderByDescending(t => t.TransferDate)); collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>() { new Filter("DestinationObjectID", s.ItemId), new Filter("DestinationObjectType", s.SmartCoreObjectType.ItemId), }, true).OrderByDescending(t => t.TransferDate)); if (parentIds != null) { collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("DestinationObjectID", parentIds), true).OrderByDescending(t => t.TransferDate)); } } var ids = collection.Select(a => a.ParentId); var components = _newLoader.GetObjectListAll <ComponentDTO, Entities.General.Accessory.Component>(new List <Filter>() { new Filter("IsBaseComponent", false), new Filter("ItemId", ids) }, true, true); var transferRecordIds = collection.Select(t => t.ItemId).ToList(); var filesDict = _filesDataAccess.GetItemFileLinks(transferRecordIds, SmartCoreType.TransferRecord.ItemId).ToDictionary(d => d.ParentId); var suppliersIds = collection.Select(t => t.FromSupplierId).ToList(); suppliersIds.AddRange(collection.Where(t => t.DestinationObjectType == SmartCoreType.Supplier).Select(t => t.DestinationObjectId).ToArray()); var suppliers = _newLoader.GetObjectListAll <SupplierDTO, Supplier>(new Filter("ItemId", suppliersIds)); var specialistIds = new List <int>(); specialistIds.AddRange(collection.Where(t => t.DestinationObjectType == SmartCoreType.Employee).Select(t => t.DestinationObjectId)); specialistIds.AddRange(collection.Select(t => t.FromSpecialistId)); var specialists = _newLoader.GetObjectListAll <SpecialistDTO, Specialist>(new Filter("ItemId", specialistIds)); foreach (var transferRecord in collection) { if (filesDict.ContainsKey(transferRecord.ItemId)) { transferRecord.Files.Add(filesDict[transferRecord.ItemId]); } #region одительский объект if (transferRecord.ParentType == SmartCoreType.BaseComponent) { var bd = _componentCore.GetBaseComponentById(transferRecord.ParentId) ?? new BaseComponent { ItemId = transferRecord.ParentId, IsDeleted = true, Description = "Can't Find Base Component with id = " + transferRecord.ParentId, PartNumber = "Unknown", SerialNumber = "Unknown" }; transferRecord.ParentComponent = bd; } else if (transferRecord.ParentType == SmartCoreType.Component) { var d = components.GetItemById(transferRecord.ParentId) ?? new Entities.General.Accessory.Component { ItemId = transferRecord.ParentId, IsDeleted = true, Description = "Can't Find Component with id = " + transferRecord.ParentId, PartNumber = "Unknown", SerialNumber = "Unknown" }; transferRecord.ParentComponent = d; } else { var d = new Entities.General.Accessory.Component { ItemId = transferRecord.ParentId, IsDeleted = true, Description = "Can't Find object with type = " + transferRecord.ParentType, PartNumber = "Unknown", SerialNumber = "Unknown" }; transferRecord.ParentComponent = d; } #endregion #region Откуда перемещен if (transferRecord.FromAircraftId > 0) { var a = _aircraftsCore.GetAircraftById(transferRecord.FromAircraftId) ?? new Aircraft { ItemId = transferRecord.FromAircraftId, IsDeleted = true, RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.FromAircraftId }; transferRecord.FromAircraft = a; } if (transferRecord.FromBaseComponentId > 0) { var bd = _componentCore.GetBaseComponentById(transferRecord.FromBaseComponentId) ?? new BaseComponent { ItemId = transferRecord.FromBaseComponentId, IsDeleted = true, Description = "Can't Find Base Component with id = " + transferRecord.FromBaseComponentId, PartNumber = "Unknown", SerialNumber = "Unknown" }; var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId); if (a != null) { bd.Aircraft = a.ToString(); } transferRecord.FromBaseComponent = bd; } if (transferRecord.FromStoreId > 0) { var store = _storeCore.GetStoreById(transferRecord.FromStoreId) ?? new Store { ItemId = transferRecord.FromStoreId, IsDeleted = true, Name = "Can't Find Store with id = " + transferRecord.FromStoreId, }; transferRecord.FromStore = store; } if (transferRecord.FromSupplierId > 0) { var supplier = suppliers.FirstOrDefault(x => x.ItemId == transferRecord.FromSupplierId) ?? new Supplier { ItemId = transferRecord.FromSupplierId, IsDeleted = true, Name = "Can't Find Supplier with id = " + transferRecord.FromSupplierId }; transferRecord.FromSupplier = supplier; } if (transferRecord.FromSpecialistId > 0) { var specialist = specialists.FirstOrDefault(x => x.ItemId == transferRecord.FromSpecialistId) ?? new Specialist { ItemId = transferRecord.FromSpecialistId, IsDeleted = true, FirstName = "Can't Find Specialist with id = " + transferRecord.FromSpecialistId }; transferRecord.FromSpecialist = specialist; } #endregion #region Куда перемещен if (transferRecord.DestinationObjectType == SmartCoreType.Store) { var store = _storeCore.GetStoreById(transferRecord.DestinationObjectId) ?? new Store { ItemId = transferRecord.DestinationObjectId, IsDeleted = true, Name = "Can't Find Store with id = " + transferRecord.DestinationObjectId, }; transferRecord.DestinationObject = store; } if (transferRecord.DestinationObjectType == SmartCoreType.BaseComponent) { var bd = _componentCore.GetBaseComponentById(transferRecord.DestinationObjectId) ?? new BaseComponent { ItemId = transferRecord.DestinationObjectId, IsDeleted = true, Description = "Can't Find Base Component with id = " + transferRecord.DestinationObjectId, PartNumber = "Unknown", SerialNumber = "Unknown" }; var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId); if (a != null) { bd.Aircraft = a.ToString(); } transferRecord.DestinationObject = bd; } if (transferRecord.DestinationObjectType == SmartCoreType.Aircraft) { var a = _aircraftsCore.GetAircraftById(transferRecord.DestinationObjectId) ?? new Aircraft { ItemId = transferRecord.DestinationObjectId, IsDeleted = true, RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.DestinationObjectId }; transferRecord.DestinationObject = a; } if (transferRecord.DestinationObjectType == SmartCoreType.Supplier) { var supplier = suppliers.FirstOrDefault(x => x.ItemId == transferRecord.DestinationObjectId) ?? new Supplier { ItemId = transferRecord.FromSupplierId, IsDeleted = true, Name = "Can't Find Supplier with id = " + transferRecord.DestinationObjectId }; transferRecord.DestinationObject = supplier; } if (transferRecord.DestinationObjectType == SmartCoreType.Employee) { var specialist = specialists.FirstOrDefault(x => x.ItemId == transferRecord.DestinationObjectId) ?? new Specialist { ItemId = transferRecord.FromSpecialistId, IsDeleted = true, FirstName = "Can't Find Specialist with id = " + transferRecord.DestinationObjectId }; transferRecord.DestinationObject = specialist; } #endregion } // возвращаем результат //SetParents(collection); return(collection); }
public AverageUtilization GetAverageUtillization(Aircraft aircraft) { var aircraftFrame = _componentCore.GetBaseComponentById(aircraft.AircraftFrameId); return(aircraftFrame.AverageUtilization); }
/// <summary> /// Загружает все элементы рабочего пакета /// </summary> /// <param name="package"></param> public void LoadDirectivePackageItems <T, TV>(T package) where T : AbstractDirectivePackage <TV>, new() where TV : BaseDirectivePackageRecord, new() { package.CanPublish = package.CanClose = true; package.BlockPublishReason = ""; package.MinClosingDate = null; package.MaxClosingDate = null; // Компоненты package.PackageRecords.Clear(); package.PackageRecords.AddRange(_loader.GetObjectListAll <TV>(BaseDirectivePackageRecord.ParentIdProperty, package.ItemId)); foreach (TV record in package.PackageRecords) { record.ParentPackage = package; } IEnumerable <IGrouping <SmartCoreType, TV> > groupedRecordsByTaskType = package.PackageRecords.GroupBy(pr => pr.PackageItemType); foreach (IGrouping <SmartCoreType, TV> groupedRecords in groupedRecordsByTaskType) { #region загрузка Базовых деталей if (groupedRecords.Key == SmartCoreType.BaseComponent) { foreach (TV adWpr in groupedRecords) { IDirective d = _componentCore.GetBaseComponentById(adWpr.DirectiveId); if (d != null) { adWpr.Task = d; } else { package.PackageRecords.RemoveById(adWpr.ItemId); } } continue; } #endregion if (groupedRecords.Key.ObjectType == null) { continue; } Type objectType = groupedRecords.Key.ObjectType; ICommonFilter filter = new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, groupedRecords.Select(wpr => wpr.DirectiveId).ToArray()); ICommonCollection directiveCollection = _loader.GetObjectCollection(objectType, new[] { filter }, true, true); if (directiveCollection.Count > 0) { foreach (TV adWpr in groupedRecords) { IDirective d = directiveCollection.GetItemById(adWpr.DirectiveId) as IDirective; if (d != null) { adWpr.Task = d; } else { package.PackageRecords.RemoveById(adWpr.ItemId); } } } } // ставим флаг о том, что все элементы рабочего пакета считаны package.PackageItemsLoaded = true; }