//Action result method reads in a id for the campaign that customers will be added to public ActionResult EditCustomerCampaign(int?id, string customerSegment, string searchString) { var customerModels = db.CustomerModels.Include(c => c.CampaignModel).Include(c => c.MarketSegmentModel); var SegmentLst = new List <string>(); var SegmentQry = from d in db.CustomerModels orderby d.MarketSegmentModel.Manufacturer select d.MarketSegmentModel.Manufacturer; //makes sure no segments are repeated in the list SegmentLst.AddRange(SegmentQry.Distinct()); ViewBag.customerSegment = new SelectList(SegmentLst); var segments = from m in db.CustomerModels select m; if (!String.IsNullOrEmpty(searchString)) { segments = segments.Where(s => s.MarketSegmentModel.Manufacturer.Contains(searchString)); } if (!string.IsNullOrEmpty(customerSegment)) { segments = segments.Where(x => x.MarketSegmentModel.Manufacturer == customerSegment); return(View(segments.ToList())); } //creates a list for reading in the customers that are wanted to be checked List <CampaignCustomerModel> customerCampaigns = new List <CampaignCustomerModel>(); foreach (var a in customerModels) { var customerCampaign1 = new CampaignCustomerModel(); customerCampaign1.CustomerID = a.CustomerID; customerCampaign1.CampaignID = id; customerCampaign1.CustomerName = a.Name; customerCampaign1.Check = false; customerCampaigns.Add(customerCampaign1); } return(View(customerCampaigns)); }
/// <summary> /// Get Campaign Customer /// </summary> /// <param name="tenantID"></param> /// <param name="userID"></param> /// <param name="campaignScriptID"></param> /// <param name="pageNo"></param> /// <param name="pageSize"></param> /// <returns></returns> public CampaignCustomerDetails GetCampaignCustomer(int tenantID, int userID, CampaingCustomerFilterRequest campaingCustomerFilterRequest) { DataSet ds = new DataSet(); CampaignCustomerDetails objdetails = new CampaignCustomerDetails(); List <CampaignCustomerModel> objList = new List <CampaignCustomerModel>(); int CustomerCount = 0; try { conn.Open(); MySqlCommand cmd = new MySqlCommand("SP_HSGetCampaignCustomer", conn) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@_TenantID", tenantID); cmd.Parameters.AddWithValue("@_UserID", userID); cmd.Parameters.AddWithValue("@_CampaignScriptID", campaingCustomerFilterRequest.CampaignScriptID); cmd.Parameters.AddWithValue("@_pageno", campaingCustomerFilterRequest.PageNo); cmd.Parameters.AddWithValue("@_pagesize", campaingCustomerFilterRequest.PageSize); cmd.Parameters.AddWithValue("@_FilterStatus", campaingCustomerFilterRequest.FilterStatus); cmd.Parameters.AddWithValue("@_MobileNumber", campaingCustomerFilterRequest.MobileNumber); MySqlDataAdapter da = new MySqlDataAdapter { SelectCommand = cmd }; da.Fill(ds); if (ds != null && ds.Tables[0] != null) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { CampaignCustomerModel obj = new CampaignCustomerModel { ID = ds.Tables[0].Rows[i]["ID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["ID"]), CampaignScriptID = ds.Tables[0].Rows[i]["CampaignScriptID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["CampaignScriptID"]), CustomerName = ds.Tables[0].Rows[i]["CustomerName"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["CustomerName"]), CustomerNumber = ds.Tables[0].Rows[i]["CustomerNumber"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["CustomerNumber"]), CustomerEmailID = ds.Tables[0].Rows[i]["CustomerEmailID"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["CustomerEmailID"]), DOB = ds.Tables[0].Rows[i]["DOB"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["DOB"]), CampaignDate = ds.Tables[0].Rows[i]["CampaignDate"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["CampaignDate"]), ResponseID = ds.Tables[0].Rows[i]["ResponseID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["ResponseID"]), CallRescheduledTo = ds.Tables[0].Rows[i]["CallRescheduledTo"] == DBNull.Value ? string.Empty : ConvertDatetimeToString(Convert.ToString(ds.Tables[0].Rows[i]["CallRescheduledTo"])), DoesTicketRaised = ds.Tables[0].Rows[i]["DoesTicketRaised"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["DoesTicketRaised"]), StatusName = ds.Tables[0].Rows[i]["StatusName"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["StatusName"]), StatusID = ds.Tables[0].Rows[i]["StatusID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["StatusID"]), Programcode = ds.Tables[0].Rows[i]["Programcode"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["Programcode"]), Storecode = ds.Tables[0].Rows[i]["Storecode"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["Storecode"]), StoreManagerId = ds.Tables[0].Rows[i]["StoreManagerId"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["StoreManagerId"]), SmsFlag = ds.Tables[0].Rows[i]["SmsFlag"] == DBNull.Value ? false : Convert.ToBoolean(ds.Tables[0].Rows[i]["SmsFlag"]), EmailFlag = ds.Tables[0].Rows[i]["EmailFlag"] == DBNull.Value ? false : Convert.ToBoolean(ds.Tables[0].Rows[i]["EmailFlag"]), MessengerFlag = ds.Tables[0].Rows[i]["MessengerFlag"] == DBNull.Value ? false : Convert.ToBoolean(ds.Tables[0].Rows[i]["MessengerFlag"]), BotFlag = ds.Tables[0].Rows[i]["BotFlag"] == DBNull.Value ? false : Convert.ToBoolean(ds.Tables[0].Rows[i]["BotFlag"]), HSCampaignResponseList = ds.Tables[1].AsEnumerable().Select(r => new HSCampaignResponse() { ResponseID = r.Field <object>("ResponseID") == DBNull.Value ? 0 : Convert.ToInt32(r.Field <object>("ResponseID")), Response = r.Field <object>("Response") == DBNull.Value ? string.Empty : Convert.ToString(r.Field <object>("Response")), Status = r.Field <object>("Status") == DBNull.Value ? 0 : Convert.ToInt32(r.Field <object>("Status")), StatusName = r.Field <object>("StatusName") == DBNull.Value ? string.Empty : Convert.ToString(r.Field <object>("StatusName")) }).ToList() }; objList.Add(obj); } } if (ds != null && ds.Tables[2] != null) { CustomerCount = ds.Tables[2].Rows[0]["TotalCustomerCount"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[2].Rows[0]["TotalCustomerCount"]); } objdetails.CampaignCustomerModel = objList; objdetails.CampaignCustomerCount = CustomerCount; } catch (Exception) { throw; } finally { if (conn != null) { conn.Close(); } if (ds != null) { ds.Dispose(); } } return(objdetails); }