public void CreateTextFile(IEnumerable <phy> phyArray) { using (raviookRemoteDBEntities db = new raviookRemoteDBEntities()) { foreach (var x in phyArray) { db.phies.Add(x); db.SaveChanges(); } } }
public ActionResult JsonCreator() { raviookRemoteDBEntities db = new raviookRemoteDBEntities(); var classId = db.phies.Select(m => m.CLASSID).Distinct(); using (StreamWriter file = new StreamWriter(@"C:\Users\Ravi kumar\Desktop\Myjson.txt")) { file.WriteLine("\"Others\" :["); foreach (var tempClassId in classId) { var others = db.phies.Where(m => m.CLASSID == tempClassId).ToList(); file.WriteLine("["); foreach (var temp in others) { file.WriteLine("{\"Category\":\"" + temp.CATEGORY + "\",\"Drug\":\"" + temp.DRUG + "\",\"ARV\":\"" + temp.ARV + "\","); file.WriteLine("\"PK\":\"" + temp.PK + "\"},"); } file.WriteLine("]ravi,"); } file.WriteLine("]"); } return(RedirectToAction("Index")); }