// GET: FilePath public ActionResult Index(int? id) { List<tbl_File_Paths> viewModel = new List<tbl_File_Paths>(); ViewBag.RequestId = id ?? 0; viewModel = new FilePathDataAccess().GetFilePath(); return View(viewModel); }
// GET: FileImport public ActionResult Index(int?Id) { ViewBag.CardTypes = new CardTypesDataAccess().GetCardTypes("A"); ViewBag.RequestId = Id ?? 0; var filePath = new FilePathDataAccess().GetFilePathByTypeID(((int)Constants.enPathType.Import).ToString()); var viewModel = FileHelper.GetFileNamesFromDirectory(filePath.Path); return(View(viewModel)); }
/// <summary> /// Sonaware: ///Field Name Index ///* Account Number 4 – AC : Account Number ///*Customer Number 37 – CP: CIF# ///Frequency Cycle Begin Date 50 – DA: Card Issuance Date(Expiry is +5 years) ///*PAN 6 – DA : Card # ///Pri/Sec Code 5 – DA : Main or Supplementary Card ///Tipper Flag 4 – DA : Card Code(*Card Type ID to be picked from Card Type table) ///Default Account 8 – AC: O: is def acct Y: linked account N: linked account ///Revised ACCeSS 3.5 Import Format For Host_2.2: CIS->IRIS ///ACCeSS Export File Utility for SonawareDotNet_1_0: IRIS->CIS /// </summary> /// <param name="request"></param> /// <returns></returns> public ActionResult AddUpdateFileImport(tbl_File_Imports request, string filePath) { List <tbl_Customer_Cards> lst = new List <tbl_Customer_Cards>(); List <ExceptionLogVM> lstExceptionLog = new List <ExceptionLogVM>(); string[] record = new string[] { }; string[] data = new string[] { }; int? cardType = null; string result = string.Empty; var currentDate = DateTime.Now; var outputFilename = $"{DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}.txt"; //var filename = "card.txt"/*"DEMO2018-27-2--16-47-25.txt"*/; //var filePath = new FilePathDataAccess().GetFilePathByTypeID(((int)Constants.enPathType.Import).ToString()); //string path = filePath?.Path ?? @"C:\"; var path = filePath; var filename = Path.GetFileName(path); // Need to Uncomment its only for testing plain file //var response = new GNUPG_Wrapper().Decrypt(Path.Combine(path, filename), outputFilename); record = FileHelper.Import(path /*outputFilename*/); //Need to Uncomment its only for testing plain file if (record != null) { data = record; /*record.Where(e => !string.IsNullOrEmpty(e) && !cardNumbers.Contains(e.Split('|')[3])).ToArray();*/ if (data.Length > 0) { for (int i = 0; i < data.Length; i++) { var datum = data[i].Split('|'); datum = datum.Length > 7 ? datum.Take(7).ToArray() : datum; if (datum.Length == 7) { var accno = datum[datum.Length - (datum.Length)]; var custno = datum[datum.Length - (datum.Length - 1)]; var strfreqdate = datum[datum.Length - (datum.Length - 2)]; var cardnum = datum[datum.Length - (datum.Length - 3)]; var priseccode = datum[datum.Length - (datum.Length - 4)]; var cardcode = datum[datum.Length - (datum.Length - 5)]; var deforlinked = datum[datum.Length - (datum.Length - 6)]; var dtfreqdate = new DateTime(int.Parse(strfreqdate.Substring(0, 4)), int.Parse(strfreqdate.Substring(4, 2)), int.Parse(strfreqdate.Substring(6, 2)), 0, 0, 0); var dtexpiry = dtfreqdate.AddYears(5); if (string.IsNullOrWhiteSpace(accno) || accno.Length != 15) { CreateExceptionLog(ref lstExceptionLog, accno, cardnum, custno, string.Format(CustomMessages.AccountNumberEmptyOrLimitExceed, 15), filename); } if (string.IsNullOrWhiteSpace(cardnum) || cardnum.Length != 16) { CreateExceptionLog(ref lstExceptionLog, accno, cardnum, custno, string.Format(CustomMessages.CardNumberEmptyOrLimitExceed, 16), filename); } if (string.IsNullOrWhiteSpace(custno) || custno.Length != 10) { CreateExceptionLog(ref lstExceptionLog, accno, cardnum, custno, string.Format(CustomMessages.CustomerNumberEmptyOrLimitExceed, 10), filename); } var requestRecord = new RequestDataAccess().GetRequestForImport(custno, accno); if (requestRecord != null) { //cardType = new CardTypesDataAccess().GetCardTypeIdByCardCode(cardcode); //request.CardTypes = Convert.ToString(cardType); var salutation = requestRecord.Salutation ?? string.Empty; var cardtitle = requestRecord.CardTitle ?? string.Empty; cardType = requestRecord.CardTypeID ?? 0; lst.Add(new tbl_Customer_Cards { AccountNo = accno, CardNo = cardnum, CardIssuance = dtfreqdate, CardExpiry = new DateTime(dtexpiry.Year, dtexpiry.Month, DateTime.DaysInMonth(dtexpiry.Year, dtexpiry.Month)), CardTypeID = cardType, Salutation = salutation, CardTitle = cardtitle, CardStatusActive = true, CIF = custno }); } else { CreateExceptionLog(ref lstExceptionLog, accno, cardnum, custno, CustomMessages.RequestNotExists, filename); } } } // Create successfull card file for T24 var filepath = new FilePathDataAccess().GetFilePathByTypeID(((int)Constants.enPathType.Export).ToString()); var fullpath = (filepath?.Path ?? string.Empty) == string.Empty ? $"{@"C:\CIS_card_file_"}{currentDate.ToString(Constants.Formats.DateFormat)}{currentDate.ToString(Constants.Formats.TimeFormat)}" : $"{filepath?.Path}\\CIS_card_file_{currentDate.ToString(Constants.Formats.DateFormat)}{currentDate.ToString(Constants.Formats.TimeFormat)}"; var fileheader = $"caRD.NUMBER,ACCT.ID1::ACCTID2"; FileHelper.WriteFile(fullpath, new string[] { fileheader }); // Add cards to customer card table foreach (var item in lst) { if (new CustomerCardDataAccess().AddCustomerCard(item)) { request.RecordCount = (request.RecordCount == null) ? 1 : ++request.RecordCount; var filedata = $"{item.CardNo},{item.AccountNo}::{item.CIF}"; FileHelper.WriteFile(fullpath, new string[] { filedata }); } else { CreateExceptionLog(ref lstExceptionLog, item.AccountNo, item.CardNo, item.CIF, CustomMessages.CardAlreadyExists, filename); } } /*new CustomerCardDataAccess().AddMultipleCustomerCard(lst);*/ // Upgrade Customer Account, link card to customer accounts lst.ForEach(e => new CustomerAccountDataAccess().UpdateCustomerAccountCardNo(e.AccountNo, e.CIF, e.CardNo)); /*request.RecordCount = (request.RecordCount ?? 0) + lst.Count;*/ } } var IsSuccess = new FileImportDataAccess().AddFileImport(request); if (IsSuccess) { AddExceptionLog(lstExceptionLog); return(Json(new { IsSuccess = IsSuccess, Response = IsSuccess, ErrorMessage = string.Format(CustomMessages.ImportRecordsRetrieveAndImport, record.Length, request.RecordCount ?? 0) }, JsonRequestBehavior.AllowGet)); } else { AddExceptionLog(lstExceptionLog); return(Json(new { IsSuccess = IsSuccess, ErrorMessage = CustomMessages.GenericErrorMessage, Response = IsSuccess }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AutomaticHotMark(HttpPostedFileBase postedFile) { long ID = 0; CustomerCardDataAccess result = new CustomerCardDataAccess(); //flag = result.CardHotMark(CardNo); string filePath = string.Empty; try { //if (postedFile != null) //{ var filePathData = new FilePathDataAccess().GetFilePathByTypeID(((int)Constants.enPathType.Import).ToString()); string path = filePathData?.Path ?? @"C:\Users\Mohsin\Desktop\ImportedFile\"; string filename = "Hotmark.csv"; //string path = Server.MapPath("~/CardHotMark/"); int found = 0, notFound = 0, alreadyhot = 0, requestexist = 0; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(filename); string extension = Path.GetExtension(filename); if (extension == ".csv" || extension == ".CSV") { //postedFile.SaveAs(filePath); string csvData = System.IO.File.ReadAllText(filePath).Replace("\r\n", "$$&$$"); //var data = csvData.Split('\n', '\r'); var data = csvData.Split(new[] { "$$&$$" }, StringSplitOptions.None).Where(e => !string.IsNullOrWhiteSpace(e)).Select(e => e.Trim()).ToArray(); var AllowedQuantity = ConfigurationManager.AppSettings["HotFile"]; int AllowedQuantityInt = Convert.ToInt32(AllowedQuantity); if (Convert.ToInt32(data.Count()) - 1 > AllowedQuantityInt) { return(Json("Please Upload maximum of " + AllowedQuantityInt + " records", JsonRequestBehavior.AllowGet)); } foreach (string row in data.Skip(1).ToList()) { //foreach (var item in row.Split(',')) //{ if (string.IsNullOrWhiteSpace(row)) { continue; } var datarow = row.Split(','); if (datarow.Length >= 2) { var cardno = datarow[0]; var expiry = new DateTime(int.Parse(datarow[1].Substring(0, 4)), int.Parse(datarow[1].Substring(4, 2)), int.Parse(datarow[1].Substring(6, 2)), 0, 0, 0); if (!string.IsNullOrEmpty(cardno)) { if (IsDuplicateEntry(cardno, "", "H", null, out ID)) { //notFound++; requestexist++; continue; } var AlreadyHot = new CustomerCardDataAccess().IsCardHotMarked(cardno); if (AlreadyHot == "Success") { var isSuccess = CardHotMarkMethods.GenerateHotMarkRequest(cardno, expiry); //var isSuccess = result.CardHotMark(cardno, expiry); if (!isSuccess) { notFound++; } else { found++; } } else { //notFound++; alreadyhot++; } } } else { return(Json("Please Select Valid .csv file", JsonRequestBehavior.AllowGet)); } //} } //TempData["mesage"] = "Sucessfully Retreived"; return(Json($"Succesfull: {found}, Card Data Not Found: {notFound},Card Already Hot: {alreadyhot},Request Already Exists: {requestexist}", JsonRequestBehavior.AllowGet)); } else { //TempData["mesage"] = "Please Select Valid .csv file"; return(Json("Please Select Valid .csv file", JsonRequestBehavior.AllowGet)); } //} } catch (Exception ex) { //TempData["mesage"] = "Path or File Not Found"; return(Json("Path or File Not Found", JsonRequestBehavior.AllowGet)); //throw ex; } // return View("CardHotMarkScreen"); }