TEXT 6
Ext cxv import controller Guest on 14th July 2025 05:50:35 AM
  1.         [HttpPost]
  2.         public async Task<ActionResult> UploadExtentionCsv(HttpPostedFileBase file)
  3.         {
  4.            
  5.  
  6.             if (file == null || file.ContentLength == 0)
  7.                 return Json(new { status = "No file" }, JsonRequestBehavior.AllowGet);
  8.  
  9.             SettingDataHandler dal = new SettingDataHandler();
  10.             try
  11.             {
  12.                
  13.                 var ExtentionList = new List<Extention>();
  14.                 var already_exists = new List<string> { };
  15.  
  16.                 using (var reader = new StreamReader(file.InputStream))
  17.                 using (var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)))
  18.                 {
  19.                     var records = csv.GetRecords<Extention>();
  20.  
  21.                     foreach (var ext in records)
  22.                     {
  23.                         if (await dal.ExtensionExistenceCheck(ext.ExtensionId))
  24.                         {
  25.                              already_exists.Add(ext.ExtensionId);
  26.                         }
  27.  
  28.                         ExtentionList.Add(ext);
  29.                     }
  30.                 }
  31.  
  32.                 Task.Run(async () =>
  33.                 {
  34.                     await add_csv_to_db(ExtentionList);
  35.                 });
  36.  
  37.                 if (already_exists == null)
  38.                 return Json(new { status = "ok" }, JsonRequestBehavior.AllowGet);
  39.                 else
  40.                     return Json(new { status = $"Thease already Exists " , extention = already_exists  } , JsonRequestBehavior.AllowGet);
  41.             }
  42.             catch (Exception ex)
  43.             {
  44.                 return Json(new { status = ex.Message }, JsonRequestBehavior.AllowGet);
  45.             }
  46.         }
  47.  
  48.         public async Task add_csv_to_db(List<Extention> ExtentionList)
  49.         {
  50.             SettingDataHandler dal = new SettingDataHandler();
  51.             GroupController g = new GroupController();
  52.             try
  53.             {
  54.                 foreach (var data in ExtentionList)
  55.                 {
  56.                     await dal.CreateExtention(data);
  57.                     await dal.AddExtionToGroup(data.GroupId.ToString(), data.ExtensionId);
  58.                 }
  59.             }
  60.             catch (Exception ex)
  61.             {
  62.             }
  63.            
  64.  
  65.         }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.