public async Task <bool> AddRmaReceiving(RMA_Receiving receiving) { if (await base.DbConnection.GetAsync <RMA_Receiving>(receiving.RMA_No) == null) { List <RMA_Receiving> uploadList = new List <RMA_Receiving>(); var idFromDb = await GetAvaliableTray(); var count = (receiving.Qty / 14) + 1; if (await GetAvaliableTrayCount() >= (receiving.Qty / 14) + 1) { for (int i = 0; i < count; i++) { RMA_Receiving uploadReceiving = new RMA_Receiving(); if (receiving.Qty > 14) { uploadReceiving.Qty = receiving.Qty - (receiving.Qty - 14); } else { uploadReceiving.Qty = receiving.Qty; } if (idFromDb != null) { uploadReceiving.Tray_ID = idFromDb[i].Tray_ID; uploadReceiving.CreateDate = DateTime.Now; uploadReceiving.CreateBy = receiving.CreateBy; uploadReceiving.PN = receiving.PN; uploadReceiving.RMA_No = receiving.RMA_No; idFromDb[i].IsEmpty = false; idFromDb[i].LastModifyBy = receiving.CreateBy; idFromDb[i].LastModifyDate = DateTime.Now; idFromDb[i].Tray_Item_Count = uploadReceiving.Qty; idFromDb[i].Current_Station_ID = 0; uploadList.Add(uploadReceiving); } receiving.Qty -= 14; } base.DbConnection.Insert(uploadList); if (idFromDb.Count > count) { idFromDb.RemoveAt(idFromDb.Count - 1); } base.DbConnection.Update(idFromDb); return(true); } else { return(false); } } return(false); }
public async Task <IActionResult> RMA_Receiving(RMA_Receiving receiving) { var isSuccess = await _repo.AddRmaReceiving(receiving); if (isSuccess) { return(NoContent()); } else { return(BadRequest("Add RMA Receiving failed!")); } }