public ActionResult Enter(DataHolder d) { //this puts each line onto a string list, and also trims each line string[] splitCharacters = new string[] { "\r\n" }; List<string> eachLine = d.DataString.Split(splitCharacters, StringSplitOptions.RemoveEmptyEntries).ToList(); eachLine = eachLine.Select(i => i.Trim()).ToList(); //gets @relation name string datasetName = eachLine.ElementAt(0).Substring(9); //add a dataset instance DataSet dataset = new DataSet { Name = datasetName }; db.DataSets.Add(dataset); db.SaveChanges(); //gets each attribute name List<string> attributeNames = new List<string>(); foreach(var line in eachLine.Where(i=>i.Length>=10 && i.Substring(0,10) == "@attribute")) { attributeNames.Add(line.Split(' ')[1]); } int data = eachLine.IndexOf("@data"); foreach (var line in eachLine.Skip(data+1)) { string instanceClass = line.Split(',')[attributeNames.Count - 1]; Instance instance = new Instance { Class = instanceClass, DataSetID = dataset.ID }; db.Instances.Add(instance); db.SaveChanges(); foreach(var attributeName in attributeNames.TakeWhile(i=>i != attributeNames.Last())) { Models.Attribute attrObj = new Models.Attribute { AttributeName = attributeName, AttributeValue = line.Split(',')[attributeNames.IndexOf(attributeName)], InstanceID = instance.ID }; db.Attributes.Add(attrObj); db.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult Enter() { DataHolder d = new DataHolder(); return View(d); }