public async Task <ActionResult> updateOrderPack([FromBody] updateOrderPackRequest updateOrderPackRequest) { String PackNo = ""; try { var order = await(from iv in db.TbtOrder where updateOrderPackRequest.DocNums.Contains(iv.DocNum) select iv).ToListAsync(); var RunNo = (from f in db.TbmRunNo where f.Type == "PackNo" select f).FirstOrDefault(); int?mRun = RunNo.RunNo; PackNo = RunningNo.GetRunNoYYYYMMdd((int)mRun); List <TbtPackItem> tbtPackItem = new List <TbtPackItem>(); foreach (var i in order) { tbtPackItem.Add( new TbtPackItem { PackNo = PackNo, CreateUser = updateOrderPackRequest.UserId, CreateDate = DateTime.Now, ItemCode = i.ItemCode, DocNum = i.DocNum }); } db.TbtPackItem.AddRange(tbtPackItem); RunNo.RunNo = mRun + 1; db.SaveChanges(); return(Ok(new { PackNo = PackNo })); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <ActionResult> updateInvoicePick([FromBody] updateInvoicePickRequest updateInvoicePickRequest) { String PickNo = ""; try { var invoice = await(from iv in db.TbtInvoice where updateInvoicePickRequest.DocNums.Contains(iv.DocNum) select iv).ToListAsync(); invoice.ForEach(i => i.FlagPick = true); var data = invoice; var RunNo = (from f in db.TbmRunNo where f.Type == "PickNo" select f).FirstOrDefault(); int?mRun = RunNo.RunNo; PickNo = RunningNo.GetRunNoYYYYMMdd((int)mRun); db.TbtOrder.AddRange(data.Select(x => new TbtOrder { Address = x.Address, BinCode = x.BinCode, CardCode = x.CardCode, CardName = x.CardName, County = x.County, CreateUser = updateInvoicePickRequest.UserId, CreateDate = DateTime.Now, Descript = x.Descript, DocDate = x.DocDate, DocDueDate = x.DocDueDate, DocNum = x.DocNum, Dscription = x.Dscription, ItemCode = x.ItemCode, Price = x.Price, Quantity = x.Quantity, Remark = x.Remark, ShipToCode = x.ShipToCode, Transporter = x.Transporter, WhsCode = x.WhsCode, Isbn = x.Isbn })); List <TbtPickItem> tbtPickItems = new List <TbtPickItem>(); foreach (var i in data) { tbtPickItems.Add( new TbtPickItem { PickNo = PickNo, CreateUser = updateInvoicePickRequest.UserId, CreateDate = DateTime.Now, ItemCode = i.ItemCode, DocNum = i.DocNum, }); } db.TbtPickItem.AddRange(tbtPickItems); RunNo.RunNo = mRun + 1; db.SaveChanges(); return(Ok(new updateInvoicePackRespone { PickNo = PickNo })); } catch (Exception ex) { return(StatusCode(500, ex)); } }