public ActionResult Index(string startdate, string enddate) { string userkey = ConfigurationManager.AppSettings["userkey"]; string uid = ConfigurationManager.AppSettings["uid"]; string LoginUser = (string)Session["LoginSAPID"]; try { TNS.TNS tns = new TNS.TNS(); DataTable dt = tns.FetchALLCampaigns("", userkey, uid); dt.TableName = "FetchCampaigns"; dt.Columns.ToString(); DateTime sdate = DateTime.ParseExact(startdate, "dd-MM-yyyy", CultureInfo.InvariantCulture); DateTime edate = DateTime.ParseExact(enddate, "dd-MM-yyyy", CultureInfo.InvariantCulture); var Campaigns = (from DataRow dr in dt.Rows orderby dr["ID"] descending where DateTime.Parse(dr["DateCreated"].ToString()) >= sdate && DateTime.Parse(dr["DateCreated"].ToString()) <= edate select new Campaign() { ID = dr["ID"].ToString(), CampaignName = dr["CampaignName"].ToString(), EmailTitle = dr["EmailTitle"].ToString(), SenderName = dr["SenderName"].ToString(), CreatedBy = dr["CreatedBy"].ToString(), DateCreated = ((DateTime)dr["DateCreated"]).ToString("dd-MMMM-yyyy"), }).ToList(); var CampaignsCount = Campaigns.Count(); ViewBag.Count = CampaignsCount; ViewBag.Startdate = startdate; ViewBag.Enddate = enddate; ViewBag.Campaigns = Campaigns; return(View()); } catch (Exception ex) { //LogError logerror = new LogError(); //logerror.ErrorLog("", LoginUser, "", "Requests/GetRequests", "Requests", "GetRequests", "FetchIncidents Error", ex.Message.ToString(), 0); ViewBag.Error = "Error Fetching Records"; return(View()); } }
public JsonResult GetCampaigns([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel) { string userkey = ConfigurationManager.AppSettings["userkey"]; string uid = ConfigurationManager.AppSettings["uid"]; //string LoginUser = (string)Session["LoginSAPID"]; try { TNS.TNS tns = new TNS.TNS(); DataTable dt = tns.FetchALLCampaigns("", userkey, uid); dt.TableName = "FetchCampaigns"; dt.Columns.ToString(); List <Campaign> Campaigns = new List <Campaign>(); int startRec = requestModel.Start; int pageSize = requestModel.Length; List <Campaign> CampaignCount = (from DataRow dr in dt.Rows select new Campaign() { ID = dr["ID"].ToString() }).ToList(); Campaigns = (from DataRow dr in dt.Rows orderby dr["ID"] descending select new Campaign() { ID = dr["ID"].ToString(), ListID = dr["ListID"].ToString(), CampaignName = dr["CampaignName"].ToString(), EmailTitle = dr["EmailTitle"].ToString(), SenderName = dr["SenderName"].ToString(), CreatedBy = dr["CreatedBy"].ToString(), DateCreated = ((DateTime)dr["DateCreated"]).ToString("dd-MMMM-yyyy"), Status = dr["Status"].ToString(), LastRunTime = dr["LastRunTime"].ToString(), NextRunTime = dr["NextRunTime"].ToString(), StartDate = dr["StartDate"].ToString(), EndDate = dr["EndDate"].ToString(), SenderEmail = dr["SenderEmail"].ToString(), Cycle = dr["Cycle"].ToString(), DeactivatedBy = dr["DeactivatedBy"].ToString(), Datedeactivated = dr["Datedeactivated"].ToString(), }).Skip(startRec).Take(pageSize).ToList(); var totalCount = CampaignCount.Count(); var filteredCount = Campaigns.Count(); if (requestModel.Search.Value != string.Empty) { var value = requestModel.Search.Value.Trim(); CampaignCount = (from DataRow dr in dt.Rows where dr["EmailTitle"].ToString().Contains(value) || dr["CampaignName"].ToString().Contains(value) select new Campaign() { ID = dr["ID"].ToString() }).ToList(); Campaigns = (from DataRow dr in dt.Rows orderby dr["ID"] descending where dr["EmailTitle"].ToString().Contains(value) || dr["CampaignName"].ToString().Contains(value) || ((DateTime)dr["DateCreated"]).ToString("dd-MMMM-yyyy").Contains(value) select new Campaign() { ID = dr["ID"].ToString(), ListID = dr["ListID"].ToString(), CampaignName = dr["CampaignName"].ToString(), EmailTitle = dr["EmailTitle"].ToString(), SenderName = dr["SenderName"].ToString(), CreatedBy = dr["CreatedBy"].ToString(), DateCreated = ((DateTime)dr["DateCreated"]).ToString("dd-MMMM-yyyy"), Status = dr["Status"].ToString(), LastRunTime = dr["LastRunTime"].ToString(), NextRunTime = dr["NextRunTime"].ToString(), StartDate = dr["StartDate"].ToString(), EndDate = dr["EndDate"].ToString(), SenderEmail = dr["SenderEmail"].ToString(), Cycle = dr["Cycle"].ToString(), DeactivatedBy = dr["DeactivatedBy"].ToString(), Datedeactivated = dr["Datedeactivated"].ToString(), }).Skip(startRec).Take(pageSize).ToList(); totalCount = CampaignCount.Count(); filteredCount = Campaigns.Count(); } var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; foreach (var column in sortedColumns) { orderByString += orderByString != String.Empty ? "," : ""; orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc"); } var data = Campaigns.Select(emList => new { ID = emList.ID, ListID = emList.ListID, CampaignName = emList.CampaignName, EmailTitle = emList.EmailTitle, SenderName = emList.SenderName, CreatedBy = emList.CreatedBy, DateCreated = emList.DateCreated, Status = emList.Status, LastRunTime = emList.LastRunTime, NextRunTime = emList.NextRunTime, StartDate = emList.StartDate, EndDate = emList.EndDate, SenderEmail = emList.SenderEmail, Cycle = emList.Cycle, DeactivatedBy = emList.DeactivatedBy, Datedeactivated = emList.Datedeactivated, }).ToList(); return(Json(new DataTablesResponse(requestModel.Draw, data, totalCount, totalCount), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { //LogError logerror = new LogError(); //logerror.ErrorLog("", LoginUser, "", "Requests/GetRequests", "Requests", "GetRequests", "FetchIncidents Error", ex.Message.ToString(), 0); return(Json(new { data = "Error has occured" }, JsonRequestBehavior.AllowGet)); } }