public async Task SaveData(TD_InStorage data) { if (data.Id.IsNullOrEmpty()) { InitEntity(data); data.StorId = _Op.Property.DefaultStorageId; foreach (var item in data.InStorDetails) { InitEntity(item); item.InStorId = data.Id; item.StorId = data.StorId; item.TotalAmt = item.Price * item.Num; } await _tD_InStorageBus.AddDataAsync(data); } else { foreach (var item in data.InStorDetails) { if (item.Id.StartsWith("newid_")) { InitEntity(item); } item.InStorId = data.Id; item.StorId = data.StorId; item.TotalAmt = item.Price * item.Num; } await _tD_InStorageBus.UpdateDataAsync(data); } }
public async Task <AjaxResult <TD_InStorage> > AutoInByTary(AutoInStorageByTary data) { var traySvc = this.serviceProvider.GetRequiredService <IPB_TrayBusiness>(); var tray = await traySvc.GetByCode(data.TrayCode); if (tray == null || !tray.LocalId.IsNullOrEmpty()) { return new AjaxResult <TD_InStorage>() { Success = false, Msg = "托盘编号错误或者托盘已入库" } } ; //var planSvc = this.serviceProvider.GetRequiredService<IPD_PlanBusiness>(); //var plan = await planSvc.GetByCode(data.PlanCode); var materialSvc = this.serviceProvider.GetRequiredService <IPB_MaterialBusiness>(); var material = await materialSvc.GetByBarcode(data.MaterialCode); var StorId = _Op.Property.DefaultStorageId; if (tray == null || material == null) { return new AjaxResult <TD_InStorage>() { Success = false, Msg = "托盘或物料输入不正确" } } ; (string StorId, string MaterialId, string TaryId)para = (StorId, material.Id, tray.Id); var localId = await _tD_InStorageBus.ReqLocation(para); if (localId.IsNullOrEmpty()) { return new AjaxResult <TD_InStorage>() { Success = false, Msg = "没有可以入库的货位" } } ; var entity = new TD_InStorage() { RecId = data.RecId, InStorTime = DateTime.Now, InType = "Product", //RefCode = data.PlanCode, Status = 0, StorId = StorId, //SupId = data.SupId, InStorDetails = new List <TD_InStorDetail>() { new TD_InStorDetail() { StorId = StorId, LocalId = localId, TrayId = tray.Id, MaterialId = material.Id, BatchNo = data.BatchNo, Num = data.Num } } }; InitEntity(entity); foreach (var item in entity.InStorDetails) { InitEntity(item); item.InStorId = entity.Id; item.TotalAmt = item.Price * item.Num; } await _tD_InStorageBus.AddDataAsync(entity); return(Success <TD_InStorage>(entity)); }