public ActionResult Create(ListHeader listHeader) { string userkey = ConfigurationManager.AppSettings["userkey"]; string uid = ConfigurationManager.AppSettings["uid"]; string LoginUser = (string)Session["LoginSAPID"]; try { TNS.TNS tns = new TNS.TNS(); var CreateList = tns.CreateListHeader(LoginUser, listHeader.Listname, listHeader.H1, listHeader.H2, listHeader.H3, listHeader.H4, listHeader.H5, listHeader.H6, listHeader.H7, listHeader.H8, listHeader.H9, listHeader.H10, listHeader.H11, listHeader.H12, listHeader.H13, listHeader.H14, listHeader.H15, listHeader.H16, listHeader.H17, listHeader.H18, listHeader.H19, listHeader.H20, userkey, uid); var CreateListStatus = CreateList.Split('~'); if (CreateListStatus[0] != "00") { TempData["Msg"] = CreateListStatus[1]; return(RedirectToAction("Index")); } else { TempData["Error"] = CreateListStatus[1]; return(RedirectToAction("Index")); } } catch (Exception ex) { //LogError logerror = new LogError(); //logerror.ErrorLog("", LoginUser, "", "Requests/GetRequests", "Requests", "GetRequests", "FetchIncidents Error", ex.Message.ToString(), 0); return(RedirectToAction("Index")); } }
public ActionResult Import(string Listname, HttpPostedFileBase upload) { string userkey = ConfigurationManager.AppSettings["userkey"]; string uid = ConfigurationManager.AppSettings["uid"]; string LoginUser = (string)Session["LoginSAPID"]; try { TNS.TNS tns = new TNS.TNS(); //var CreateList = tns.CreateListHeader(LoginUser, listHeader.Listname, listHeader.H1, listHeader.H2, listHeader.H3, listHeader.H4, listHeader.H5, listHeader.H6, listHeader.H7, listHeader.H8, listHeader.H9, listHeader.H10, listHeader.H11, listHeader.H12, listHeader.H13, listHeader.H14, listHeader.H15, listHeader.H16, listHeader.H17, listHeader.H18, listHeader.H19, listHeader.H20, userkey, uid); //var CreateListStatus = CreateList.Split('~'); if (upload != null && upload.ContentLength > 0) { if (upload.FileName.EndsWith(".csv")) { // Read the file as a stream StreamReader streamCsv = new StreamReader(upload.InputStream); string csvDataLine = ""; int CurrentLine = 0; string[] PersonData = null; string[] headerData = null; string listCreated = ""; string headerLine = streamCsv.ReadLine(); headerData = headerLine.Split(','); var colHeader = headerData.Count(); if (colHeader == 1) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 2) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 3) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 4) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 5) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 6) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 7) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 8) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 9) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 10) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 11) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 12) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], "", "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 13) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], "", "", "", "", "", "", "", userkey, uid); } else if (colHeader == 14) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], "", "", "", "", "", "", userkey, uid); } else if (colHeader == 15) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], headerData[14], "", "", "", "", "", userkey, uid); } else if (colHeader == 16) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], headerData[14], headerData[15], "", "", "", "", userkey, uid); } else if (colHeader == 17) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], headerData[14], headerData[15], headerData[16], "", "", "", userkey, uid); } else if (colHeader == 18) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], headerData[14], headerData[15], headerData[16], headerData[17], "", "", userkey, uid); } else if (colHeader == 19) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], headerData[14], headerData[15], headerData[16], headerData[17], headerData[18], "", userkey, uid); } else if (colHeader == 20) { listCreated = tns.CreateListHeader(LoginUser, Listname, headerData[0], headerData[1], headerData[2], headerData[3], headerData[4], headerData[5], headerData[6], headerData[7], headerData[8], headerData[9], headerData[10], headerData[11], headerData[12], headerData[13], headerData[14], headerData[15], headerData[16], headerData[17], headerData[18], headerData[19], userkey, uid); } var CreateListStatus = listCreated.Split('~'); if (CreateListStatus[0] != "00") { TempData["Msg"] = CreateListStatus[2]; return(RedirectToAction("Index")); } else { while ((csvDataLine = streamCsv.ReadLine()) != null) { if (CurrentLine != -1) { PersonData = csvDataLine.Split(','); var colCount = PersonData.Count(); if (colCount == 1) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 2) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 3) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 4) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 5) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 6) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], "", "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 7) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], "", "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 8) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], "", "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 9) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], "", "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 10) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], "", "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 11) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], "", "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 12) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], "", "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 13) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], "", "", "", "", "", "", "", userkey, uid); } else if (colCount == 14) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], "", "", "", "", "", "", userkey, uid); } else if (colCount == 15) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], PersonData[14], "", "", "", "", "", userkey, uid); } else if (colCount == 16) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], PersonData[14], PersonData[15], "", "", "", "", userkey, uid); } else if (colCount == 17) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], PersonData[14], PersonData[15], PersonData[16], "", "", "", userkey, uid); } else if (colCount == 18) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], PersonData[14], PersonData[15], PersonData[16], PersonData[17], "", "", userkey, uid); } else if (colCount == 19) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], PersonData[14], PersonData[15], PersonData[16], PersonData[17], PersonData[18], "", userkey, uid); } else if (colCount == 20) { var listContentCreated = tns.CreateListContent(LoginUser, CreateListStatus[1], PersonData[0], PersonData[1], PersonData[2], PersonData[3], PersonData[4], PersonData[5], PersonData[6], PersonData[7], PersonData[8], PersonData[9], PersonData[10], PersonData[11], PersonData[12], PersonData[13], PersonData[14], PersonData[15], PersonData[16], PersonData[17], PersonData[18], PersonData[19], userkey, uid); } } CurrentLine += 1; } TempData["MessageSuccess"] = "Contact Imported Successfully"; return(RedirectToAction("index", "Lists")); } } else { TempData["MessageError"] = "File Format is not Supported"; return(RedirectToAction("Upload", "Lists")); } } else { TempData["MessageError"] = "Please Add File"; return(RedirectToAction("Upload", "Lists")); } } catch (Exception ex) { TempData["MessageError"] = "Error:" + ex.Message; //LogError logerror = new LogError(); //logerror.ErrorLog("", LoginUser, "", "Requests/GetRequests", "Requests", "GetRequests", "FetchIncidents Error", ex.Message.ToString(), 0); return(RedirectToAction("Index")); } }