public void SaveScannedBarcodeToTextFile(string barcode, long salesReturnId) { SuccessErrorModel model = new SuccessErrorModel(); try { int branchId = Convert.ToInt32(Session["BranchId"]); var scannedBarCode = barcode.ToUpper(); int productId = Convert.ToInt32(scannedBarCode.Substring(2, 3)); var returndetailsbyId = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList().FirstOrDefault(n => n.SalesReturnId == salesReturnId); var filePath = GetReceiveProductFilePath(salesReturnId, branchId); //------------read Scanned barcode form text file--------- var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList(); //------------Load receiveable product--------- var receivesProductList = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList(); List <ViewProduct> products = _iDeliveryManager.GetDeliveredProductListByTransactionRef(returndetailsbyId.DeliveryRef).ToList(); var receivesProductCodeList = products.Select(n => n.ProductBarCode).ToList(); var isvalid = Validator.ValidateProductBarCode(scannedBarCode); int requistionQtyByProductId = receivesProductList.ToList().FindAll(n => n.ProductId == productId).Sum(n => n.Quantity); int scannedQtyByProductId = barcodeList .FindAll(n => Convert.ToInt32(n.ProductCode.Substring(2, 3)) == productId).Count; bool isScannComplete = requistionQtyByProductId.Equals(scannedQtyByProductId); if (isScannComplete) { model.Message = "<p style='color:green'> Scanned Complete</p>"; // return Json(model, JsonRequestBehavior.AllowGet); } else if (!isvalid) { model.Message = "<p style='color:red'> Invalid Barcode</p>"; //return Json(model, JsonRequestBehavior.AllowGet); } else if (receivesProductCodeList.Contains(scannedBarCode)) { _iProductManager.AddProductToTextFile(scannedBarCode, filePath); } } catch (FormatException exception) { Log.WriteErrorLog(exception); model.Message = "<p style='color:red'>" + exception.GetType() + "</p>"; //return Json(model, JsonRequestBehavior.AllowGet); } catch (Exception exception) { Log.WriteErrorLog(exception); model.Message = "<p style='color:red'>" + exception.Message + "</p>"; // return Json(model, JsonRequestBehavior.AllowGet); } // return Json(model, JsonRequestBehavior.AllowGet); }