private void CreateProjectSnapshot(QuiltContext ctx, Project dbProject, long designSnapshotId, MProject_ProjectSpecification data, DateTime utcNow) { var dbArtifact = new Artifact() { ArtifactTypeCode = data.ProjectArtifactTypeCode, // ArtifactTypes.Kit ArtifactValueTypeCode = data.ProjectArtifactValueTypeCode, // ArtifactValueTypes.Json Value = data.ProjectArtifactValue }; _ = ctx.Artifacts.Add(dbArtifact); var dbProjectSnapshot = new ProjectSnapshot() { Project = dbProject, ProjectSnapshotSequence = dbProject.CurrentProjectSnapshotSequence, Name = dbProject.Name, DesignSnapshotId = designSnapshotId, Artifact = dbArtifact, CreateDateTimeUtc = utcNow, UpdateDateTimeUtc = utcNow, }; _ = ctx.ProjectSnapshots.Add(dbProjectSnapshot); foreach (var component in data.Components) { var mInventoryItem = InventoryMicroService.GetEntry(component.Sku); var consumableReference = CreateConsumableReference.FromInventoryItemId(mInventoryItem.InventoryItemId); var dbProjectSnapshotComponent = dbProjectSnapshot.ProjectSnapshotComponents.Where(r => r.ConsumableReference == consumableReference && r.UnitOfMeasureCodeNavigation == ctx.UnitOfMeasure(component.UnitOfMeasureCode)).SingleOrDefault(); if (dbProjectSnapshotComponent != null) { dbProjectSnapshotComponent.Quantity += component.Quantity; } else { dbProjectSnapshotComponent = new ProjectSnapshotComponent() { ProjectSnapshot = dbProjectSnapshot, ProjectSnapshotComponentSequence = dbProjectSnapshot.ProjectSnapshotComponents.Count + 1, ConsumableReference = consumableReference, UnitOfMeasureCode = component.UnitOfMeasureCode, Quantity = component.Quantity, }; _ = ctx.ProjectSnapshotComponents.Add(dbProjectSnapshotComponent); } } }
public static MProject_ProjectSnapshotComponent MProject_ProjectSnapshotComponent(ProjectSnapshotComponent dbProjectSnapshotComponent, MInventory_LibraryEntry mInventoryItem, InventoryItemType dbInventoryItemType, UnitOfMeasure dbUnitOfMeasure, decimal unitPrice, decimal totalPrice) { return(new MProject_ProjectSnapshotComponent() { ProjectSnapshotComponentId = dbProjectSnapshotComponent.ProjectSnapshotComponentId, Description = mInventoryItem.Name, Quantity = dbProjectSnapshotComponent.Quantity, UnitPrice = unitPrice, TotalPrice = totalPrice, ConsumableReference = CreateConsumableReference.FromInventoryItemId(mInventoryItem.InventoryItemId), Sku = mInventoryItem.Sku, UnitOfMeasure = GetValue.MCommon_UnitOfMeasure(dbUnitOfMeasure.UnitOfMeasureCode), UnitOfMeasureName = dbUnitOfMeasure.Name, Category = dbInventoryItemType.Name, Collection = mInventoryItem.Collection, Manufacturer = mInventoryItem.Manufacturer }); }