public async Task <int> CreateAsync(GarmentLeftoverWarehouseReceiptAccessory model) { using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { int Created = 0; model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); model.InvoiceNoReceive = GenerateNo(model); foreach (var item in model.Items) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock { ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.ACCESSORIES, UnitId = model.RequestUnitId, UnitCode = model.RequestUnitCode, UnitName = model.RequestUnitName, PONo = item.POSerialNumber, UomId = item.UomUnitId, UomUnit = item.UomUnit, Quantity = item.Quantity, ProductCode = item.ProductCode, ProductId = item.ProductId, ProductName = item.ProductName, BasicPrice = item.BasicPrice }; await StockService.StockIn(stock, model.InvoiceNoReceive, model.Id, item.Id); } await UpdateUnitExpenditureNoteIsReceived(model.UENid, true); transaction.Commit(); return(Created); } catch (Exception e) { transaction.Rollback(); throw e; } } }
public async Task <int> UpdateAsync(int id, GarmentLeftoverWarehouseReceiptAccessory model) { int Updated = 0; using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { GarmentLeftoverWarehouseReceiptAccessory existingModel = await DbSet.Where(w => w.Id == id).FirstOrDefaultAsync(); //if (existingModel.InvoiceNoReceive != model.InvoiceNoReceive) //{ // existingModel.InvoiceNoReceive = model.InvoiceNoReceive; //} //if (existingModel.RequestUnitCode != model.RequestUnitCode) //{ // existingModel.RequestUnitCode = model.RequestUnitCode; //} //if (existingModel.RequestUnitId != model.RequestUnitId) //{ // existingModel.RequestUnitId = model.RequestUnitId; //} //if (existingModel.RequestUnitName != model.RequestUnitName) //{ // existingModel.RequestUnitName = model.RequestUnitName; //} //if (existingModel.StorageFromName != model.StorageFromName) //{ // existingModel.StorageFromName = model.StorageFromName; //} //if (existingModel.StorageFromId != model.StorageFromId) //{ // existingModel.StorageFromId = model.StorageFromId; //} //if (existingModel.StorageFromCode != model.StorageFromCode) //{ // existingModel.StorageFromCode = model.StorageFromCode; //} if (existingModel.StorageReceiveDate != model.StorageReceiveDate) { existingModel.StorageReceiveDate = model.StorageReceiveDate; } //if (existingModel.UENid != model.UENid) //{ // existingModel.UENid = model.UENid; //} //if (existingModel.UENNo != model.UENNo) //{ // existingModel.UENNo = model.UENNo; //} if (existingModel.Remark != model.Remark) { existingModel.Remark = model.Remark; } //if (model.AvalType == "AVAL FABRIC") //{ // if (existingModel.TotalAval != model.TotalAval) // { // GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock // { // ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.AVAL_FABRIC, // UnitId = model.UnitFromId, // UnitCode = model.UnitFromCode, // UnitName = model.UnitFromName, // Quantity = existingModel.TotalAval // }; // await StockService.StockOut(stock, existingModel.AvalReceiptNo, model.Id, 0); // GarmentLeftoverWarehouseStock stock1 = new GarmentLeftoverWarehouseStock // { // ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.AVAL_FABRIC, // UnitId = model.UnitFromId, // UnitCode = model.UnitFromCode, // UnitName = model.UnitFromName, // Quantity = model.TotalAval // }; // await StockService.StockIn(stock1, model.AvalReceiptNo, model.Id, 0); // existingModel.TotalAval = model.TotalAval; // } //} existingModel.FlagForUpdate(IdentityService.Username, UserAgent); Updated = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } return(Updated); }