public ActionResult Delete_Prospective(string listid) { string msg = ""; try { if (listid != "") { var data = context.UserProspectingLists.Where(x => x.listid.Contains(listid)).ToList(); foreach (var i in data) { string[] ids = Array.ConvertAll(i.listid.Split(','), element => element.ToString()); if (ids.Contains(listid)) { ids = ids.Where(val => val != listid).ToArray(); if (ids.Count() > 0) { string idString = String.Join(",", ids); context.SpUpdateUserPRos(@i.UserId, idString); context.SaveChanges(); } else { context.Spdeletedatauserprospecting(@i.Id); context.SaveChanges(); } } } context.SpdeleteProspect(Convert.ToInt32(listid)); context.SaveChanges(); msg = "Record Deleted"; TempData["Message"] = msg; } } catch (Exception ex) { cm.ErrorExceptionLogingByService(ex.ToString(), "ProspectListsClient" + ":" + new StackTrace().GetFrame(0).GetMethod().Name, "Save_Role", "NA", "NA", "NA", "WEB"); msg = "Error Occured"; TempData["Message"] = msg; } return(RedirectToAction("Index")); }