public async Task <int> InsertSingle(CostCalculationModel createModel) { do { createModel.Code = CodeGenerator.Generate(); }while (_costCalculationDbSet.Any(entity => entity.Code.Equals(createModel.Code))); EntityExtension.FlagForCreate(createModel, _identityService.Username, UserAgent); createModel.Machines.ToList().ForEach(machine => { EntityExtension.FlagForCreate(machine, _identityService.Username, UserAgent); machine.Chemicals.ToList().ForEach(chemical => { EntityExtension.FlagForCreate(chemical, _identityService.Username, UserAgent); }); }); _costCalculationDbSet.Add(createModel); await _dbContext.SaveChangesAsync(); var chemicalModels = createModel.Machines.ToList().SelectMany(entity => { var result = entity.Chemicals.ToList().Select(chemical => { chemical.CostCalculationId = createModel.Id; return(chemical); }); return(result); }); _costCalculationChemicalDbSet.UpdateRange(chemicalModels); return(await _dbContext.SaveChangesAsync()); }
public CostCalculationPagedListData(CostCalculationModel entity) { Id = entity.Id; ProductionOrderNo = entity.ProductionOrderNo; LastModifiedUtc = entity.LastModifiedUtc; InstructionName = entity.InstructionName; Date = entity.Date; GreigeName = entity.GreigeName; BuyerName = entity.BuyerName; }
public CostCalculationViewModel(CostCalculationModel costCalculation, List <CostCalculationMachineModel> costCalculationMachines, List <CostCalculationChemicalModel> costCalculationChemicals) { Id = costCalculation.Id; InstructionId = costCalculation.InstructionId; PreparationValue = costCalculation.PreparationValue; CurrencyRate = costCalculation.CurrencyRate; ProductionUnitValue = costCalculation.ProductionUnitValue; TKLQuantity = costCalculation.TKLQuantity; GreigeId = costCalculation.GreigeId; PreparationFabricWeight = costCalculation.PreparationFabricWeight; RFDFabricWeight = costCalculation.RFDFabricWeight; ActualPrice = costCalculation.ActualPrice; CargoCost = costCalculation.CargoCost; InsuranceCost = costCalculation.InsuranceCost; Remark = costCalculation.Remark; Machines = costCalculationMachines.Select(entity => new CostCalculationMachineViewModel(entity, costCalculationChemicals)).ToList(); }