public async Task <FinishingPrintingSalesContractModel> ReadByIdAsync(int id) { return(await finishingPrintingSalesContractLogic.ReadByIdAsync(id)); }
public async Task <int> CreateAsync(ProductionOrderModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { //List<object> productionOrderModelTemp = new List<object>(); //List<ProductionOrder_DetailModel> DetailsTemp = new List<ProductionOrder_DetailModel>(); //foreach (ProductionOrder_DetailModel dataTemp in model.Details) //{ // DetailsTemp.Add(dataTemp); //} //ProductionOrderModel productionOrderModel = new ProductionOrderModel(); //productionOrderModel = model; //for (int i = 0; i < DetailsTemp.Count; i++) //{ // List<ProductionOrder_RunWidthModel> runWidthTemp = new List<ProductionOrder_RunWidthModel>(); // if (model.RunWidths.Count > 0) // { // foreach (ProductionOrder_RunWidthModel runWidth in model.RunWidths) // { // runWidthTemp.Add(runWidth); // } // } // productionOrderModel.RunWidths = runWidthTemp; // List<ProductionOrder_LampStandardModel> LampStandardsTemp = new List<ProductionOrder_LampStandardModel>(); // foreach (ProductionOrder_LampStandardModel LampStandardModel in model.LampStandards) // { // LampStandardsTemp.Add(LampStandardModel); // } // productionOrderModel.LampStandards = LampStandardsTemp; // do // { // productionOrderModel.Code = CodeGenerator.Generate(); // } // while (DbSet.Any(d => d.Code.Equals(productionOrderModel.Code))); // index += i; // ProductionOrderNumberGenerator(productionOrderModel, index); // var temp = productionOrderModel.Clone(); // productionOrderLogic.Create(temp); //} int index = 0; foreach (var item in model.Details) { ProductionOrderModel productionOrder = new ProductionOrderModel() { 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))); ProductionOrderNumberGenerator(productionOrder, index); 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 <int> CreateAsync(ProductionOrderModel model) { using (var transaction = DbContext.Database.BeginTransaction()) { try { List <object> productionOrderModelTemp = new List <object>(); List <ProductionOrder_DetailModel> DetailsTemp = new List <ProductionOrder_DetailModel>(); foreach (ProductionOrder_DetailModel dataTemp in model.Details) { DetailsTemp.Add(dataTemp); } ProductionOrderModel productionOrderModel = new ProductionOrderModel(); productionOrderModel = model; for (int i = 0; i < DetailsTemp.Count; i++) { List <ProductionOrder_RunWidthModel> runWidthTemp = new List <ProductionOrder_RunWidthModel>(); if (model.RunWidths.Count > 0) { foreach (ProductionOrder_RunWidthModel runWidth in model.RunWidths) { runWidthTemp.Add(runWidth); } } productionOrderModel.RunWidths = runWidthTemp; List <ProductionOrder_LampStandardModel> LampStandardsTemp = new List <ProductionOrder_LampStandardModel>(); foreach (ProductionOrder_LampStandardModel LampStandardModel in model.LampStandards) { LampStandardsTemp.Add(LampStandardModel); } productionOrderModel.LampStandards = LampStandardsTemp; do { productionOrderModel.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(productionOrderModel.Code))); ProductionOrderNumberGenerator(productionOrderModel); var temp = productionOrderModel.Clone(); productionOrderLogic.Create(temp); } FinishingPrintingSalesContractModel dataFPSalesContract = await finishingPrintingSalesContractLogic.ReadByIdAsync(Convert.ToInt32(productionOrderModel.SalesContractId)); if (dataFPSalesContract != null) { dataFPSalesContract.RemainingQuantity = dataFPSalesContract.RemainingQuantity - model.OrderQuantity; this.finishingPrintingSalesContractLogic.UpdateAsync(Convert.ToInt32(dataFPSalesContract.Id), dataFPSalesContract); } } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(await DbContext.SaveChangesAsync()); }