public ActionResult Create(PmeViewModel viewModel, IEnumerable <HttpPostedFileBase> files) { var pme = new Pme.Models.Pme(); pme.ProgrameCode = viewModel.ProgrameCode; pme.ProgrameVersionCode = viewModel.ProgrameVersionCode; pme.Version = viewModel.Version; pme.AppMapPackageId = viewModel.AppMapPackageId; var pmeDetails = new List <PmeDetail>(); foreach (var item in files) { var reader = new StreamReader(item.InputStream); reader.ReadLine(); while (!reader.EndOfStream) { var pmeDetail = new PmeDetail(); var line = reader.ReadLine(); var values = line.Split(','); pmeDetail.Clocking = values[0]; pmeDetail.Cpu = values[1]; pmeDetail.Maximum = values[2]; pmeDetail.Memory = values[3]; pmeDetail.Minimum = values[4]; pmeDetail.Threshold = values[5]; pmeDetails.Add(pmeDetail); } } DAL.PmeContext context = new DAL.PmeContext(); context.Save(pme, pmeDetails); return(RedirectToAction("Index")); }
public void Save(Pme.Models.Pme pme, List <PmeDetail> pmeDetails) { var savedPme = Pmes.Add(pme); savedPme.PmeDetails = new List <PmeDetail>(); foreach (var item in pmeDetails) { pme.PmeDetails.Add(item); } SaveChanges(); }