public JsonResult SaveScannedBarcodeToXmlFile(string barcode, int userId, DateTime saleDate) { SuccessErrorModel model = new SuccessErrorModel(); try { string scannedBarCode = barcode.ToUpper(); if (barcode.Length == 8) { var barcodeModel = _iBarCodeManager.GetBarcodeByBatchCode(barcode); scannedBarCode = barcodeModel.Barcode; } int branchId = Convert.ToInt32(Session["BranchId"]); var filePath = SoldProductXmlFilePath(branchId, userId); var barcodeList = _iProductManager.GetTempSoldBarcodesFromXmlFile(filePath).Select(n => n.BarCode); bool isScannedBefore = barcodeList.Contains(scannedBarCode); ViewDisributedProduct product; bool isSoldFromFactory = _iReportManager.IsDistributedFromFactory(scannedBarCode); //var updatedInFactory = _iReportManager.IsAllreadyUpdatedSaleDateInFactory(scannedBarCode); bool isUPdatedSaleDate = _iReportManager.IsAllreadyUpdatedSaleDate(scannedBarCode); //var updatedInBranch = _iReportManager.IsAllreadyUpdatedSaleDateInBranch(scannedBarCode); bool isSoldFromBranch = _iReportManager.IsDistributedFromBranch(scannedBarCode); bool isReplaceDelivery = _iReportManager.IsDeliveryForReplace(scannedBarCode); if (isScannedBefore) { model.Message = "<p style='color:red'> Already Added!</p>"; //return Json(model, JsonRequestBehavior.AllowGet); } else if (isUPdatedSaleDate) { model.Message = "<p style='color:red'>Sale date Already Updated!</p>"; //return Json(model, JsonRequestBehavior.AllowGet); } else if (isSoldFromBranch) { product = _iReportManager.GetDistributedProductFromBranch(scannedBarCode); product.SaleDate = saleDate; _iProductManager.AddBarCodeToTempSoldProductXmlFile(product, scannedBarCode, filePath); } else if (isSoldFromFactory) { product = _iReportManager.GetDistributedProductFromFactory(scannedBarCode); product.SaleDate = saleDate; _iProductManager.AddBarCodeToTempSoldProductXmlFile(product, scannedBarCode, filePath); } else if (isReplaceDelivery) { product = _iReportManager.GetReplaceDistributedProduct(scannedBarCode); product.SaleDate = saleDate; _iProductManager.AddBarCodeToTempSoldProductXmlFile(product, scannedBarCode, filePath); } else { model.Message = "<p style='color:red'>Failed to add list!</p>"; } } catch (FormatException exception) { Log.WriteErrorLog(exception); model.Message = "<p style='color:red'>Failed to add list!</p>"; } catch (Exception exception) { Log.WriteErrorLog(exception); model.Message = "<p style='color:red'>Failed to add list!</p>"; } return(Json(model, JsonRequestBehavior.AllowGet)); }