public async Task <int> CreateAsync(ProductionOrderModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { int index = 0; foreach (var item in model.Details) { ProductionOrderModel productionOrder = new ProductionOrderModel() { UnitCode = model.UnitCode, UnitId = model.UnitId, UnitName = model.UnitName, AccountId = model.AccountId, AccountUserName = model.AccountUserName, Active = model.Active, ArticleFabricEdge = model.ArticleFabricEdge, AutoIncreament = model.AutoIncreament, BuyerCode = model.BuyerCode, BuyerId = model.BuyerId, BuyerName = model.BuyerName, BuyerType = model.BuyerType, Code = model.Code, CreatedAgent = model.CreatedAgent, CreatedBy = model.CreatedBy, CreatedUtc = model.CreatedUtc, DeletedAgent = model.DeletedAgent, DeletedBy = model.DeletedBy, DeletedUtc = model.DeletedUtc, DeliveryDate = model.DeliveryDate, DesignCode = model.DesignCode, DesignMotiveCode = model.DesignMotiveCode, DesignMotiveID = model.DesignMotiveID, DesignMotiveName = model.DesignMotiveName, DesignNumber = model.DesignNumber, DistributedQuantity = model.DistributedQuantity, FinishTypeCode = model.FinishTypeCode, FinishTypeId = model.FinishTypeId, FinishTypeName = model.FinishTypeName, FinishTypeRemark = model.FinishTypeRemark, FinishWidth = model.FinishWidth, HandlingStandard = model.HandlingStandard, Id = model.Id, IsClosed = model.IsClosed, IsCompleted = model.IsCompleted, IsDeleted = model.IsDeleted, IsRequested = model.IsRequested, IsCalculated = model.IsCalculated, IsUsed = model.IsUsed, LastModifiedAgent = model.LastModifiedAgent, LastModifiedBy = model.LastModifiedBy, LastModifiedUtc = model.LastModifiedUtc, MaterialCode = model.MaterialCode, MaterialConstructionCode = model.MaterialConstructionCode, MaterialConstructionId = model.MaterialConstructionId, MaterialConstructionName = model.MaterialConstructionName, MaterialConstructionRemark = model.MaterialConstructionRemark, MaterialId = model.MaterialId, MaterialName = model.MaterialName, MaterialOrigin = model.MaterialOrigin, MaterialPrice = model.MaterialPrice, MaterialTags = model.MaterialTags, MaterialWidth = model.MaterialWidth, OrderNo = model.OrderNo, OrderQuantity = item.Quantity, OrderTypeCode = model.OrderTypeCode, OrderTypeId = model.OrderTypeId, OrderTypeName = model.OrderTypeName, OrderTypeRemark = model.OrderTypeRemark, PackingInstruction = model.PackingInstruction, ProcessTypeCode = model.ProcessTypeCode, ProcessTypeId = model.ProcessTypeId, ProcessTypeName = model.ProcessTypeName, ProcessTypeRemark = model.ProcessTypeRemark, ProfileFirstName = model.ProfileFirstName, ProfileGender = model.ProfileGender, ProfileLastName = model.ProfileLastName, Remark = model.Remark, Run = model.Run, SalesContractId = model.SalesContractId, SalesContractNo = model.SalesContractNo, Sample = model.Sample, ShippingQuantityTolerance = model.ShippingQuantityTolerance, ShrinkageStandard = model.ShrinkageStandard, StandardTestCode = model.StandardTestCode, StandardTestId = model.StandardTestId, StandardTestName = model.StandardTestName, StandardTestRemark = model.StandardTestRemark, UId = model.UId, UomId = model.UomId, UomUnit = model.UomUnit, YarnMaterialCode = model.YarnMaterialCode, YarnMaterialId = model.YarnMaterialId, YarnMaterialName = model.YarnMaterialName, YarnMaterialRemark = model.YarnMaterialRemark, Details = new List <ProductionOrder_DetailModel> { item }, LampStandards = model.LampStandards != null?model.LampStandards.Select(x => new ProductionOrder_LampStandardModel() { Active = x.Active, Code = x.Code, CreatedAgent = x.CreatedAgent, CreatedBy = x.CreatedBy, CreatedUtc = x.CreatedUtc, DeletedAgent = x.DeletedAgent, DeletedBy = x.DeletedBy, DeletedUtc = x.DeletedUtc, Description = x.Description, Id = x.Id, IsDeleted = x.IsDeleted, LampStandardId = x.LampStandardId, LastModifiedAgent = x.LastModifiedAgent, LastModifiedBy = x.LastModifiedBy, LastModifiedUtc = x.LastModifiedUtc, Name = x.Name, ProductionOrderModel = x.ProductionOrderModel, UId = x.UId }).ToArray() : new ProductionOrder_LampStandardModel[0], RunWidths = model.RunWidths != null?model.RunWidths.Select(x => new ProductionOrder_RunWidthModel() { Value = x.Value, Active = x.Active, CreatedAgent = x.CreatedAgent, CreatedBy = x.CreatedBy, CreatedUtc = x.CreatedUtc, IsDeleted = x.IsDeleted, DeletedAgent = x.DeletedAgent, DeletedBy = x.DeletedBy, DeletedUtc = x.DeletedUtc, Id = x.Id, LastModifiedAgent = x.LastModifiedAgent, LastModifiedBy = x.LastModifiedBy, LastModifiedUtc = x.LastModifiedUtc, ProductionOrderModel = x.ProductionOrderModel, UId = x.UId }).ToArray() : new ProductionOrder_RunWidthModel[0] }; do { productionOrder.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(productionOrder.Code))); productionOrderLogic.Create(productionOrder); index++; } FinishingPrintingSalesContractModel dataFPSalesContract = await finishingPrintingSalesContractLogic.ReadByIdAsync(model.SalesContractId); if (dataFPSalesContract != null) { dataFPSalesContract.RemainingQuantity = dataFPSalesContract.RemainingQuantity - model.OrderQuantity; this.finishingPrintingSalesContractLogic.UpdateAsync(dataFPSalesContract.Id, dataFPSalesContract); } result = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(result); }
public async Task <FinishingPrintingSalesContractModel> ReadByIdAsync(int id) { return(await finishingPrintingSalesContractLogic.ReadByIdAsync(id)); }