public Guid UpdateSeismosClient(KeyValueEntity seismosKeyValueEntity) { Guid retGuid; using (var seismosContext = new seismosEntities()) { SeismosClient updateSeismosClient; bool bNew = false; if (seismosKeyValueEntity.Id == Guid.Empty) { updateSeismosClient = new SeismosClient { Id = Guid.NewGuid() }; bNew = true; } else { updateSeismosClient = seismosContext.SeismosClients.FirstOrDefault(sc => sc.Id == seismosKeyValueEntity.Id); } if (updateSeismosClient == null) { return(Guid.Empty); } foreach (var keyValuePair in seismosKeyValueEntity.KeyValuePairs) { switch (keyValuePair.Id) { case ClientName: updateSeismosClient.ClientName = keyValuePair.Text.ToString(); break; case ContactName: updateSeismosClient.Contact = keyValuePair.Text.ToString(); break; case EmailAddress: updateSeismosClient.Email = keyValuePair.Text.ToString(); break; case PhoneNumber: updateSeismosClient.PhoneNumber = keyValuePair.Text.ToString(); break; } } if (bNew) { seismosContext.SeismosClients.Add(updateSeismosClient); } retGuid = updateSeismosClient.Id; seismosContext.SaveChanges(); } return(retGuid); }
public KeyValueEntity GetWellNamesEntity(Guid seismosProjectId) { KeyValueEntity wellsEntity = new KeyValueEntity(); SeismosProject targetProject; List <Well> wells; using (var seismosContext = new seismosEntities()) { targetProject = seismosContext.SeismosProjects.FirstOrDefault(sp => sp.Id == seismosProjectId); if (targetProject == null) { return(null); } // wells = seismosContext.Wells.Where(w => w.SeismosProject.Id == targetProject.Id).ToList(); wells = targetProject.Wells.ToList(); wellsEntity.Id = targetProject.Id; wellsEntity.Name = targetProject.Name; foreach (var well in wells) { int numStages = 0; var treatments = seismosContext.Treatments.Where(tr => tr.WellId == well.Id).ToList(); foreach (var treatment in treatments) { if (treatment is HydraulicFracturingTreatment fracturingTreatment) { numStages += fracturingTreatment.Stages.Count(); } } wellsEntity.KeyValuePairs.Add(new KeyValueMutable <string, object>(well.WellName, numStages.ToString())); } } return(wellsEntity); }
public Guid UpdateSeismosProject(KeyValueEntity seismosKeyValueEntity, Guid seismosClientId) { Guid retGuid; using (var seismosContext = new seismosEntities()) { SeismosProject updateSeismoProject; bool bNew = false; if (seismosKeyValueEntity.Id == Guid.Empty) { updateSeismoProject = new SeismosProject { Id = Guid.NewGuid() }; bNew = true; } else { updateSeismoProject = seismosContext.SeismosProjects.FirstOrDefault(sc => sc.Id == seismosKeyValueEntity.Id); } if (updateSeismoProject == null) { return(Guid.Empty); } updateSeismoProject.SeismosClientId = seismosClientId; foreach (var keyValuePair in seismosKeyValueEntity.KeyValuePairs) { switch (keyValuePair.Id) { case ProjectName: updateSeismoProject.Name = keyValuePair.Text.ToString(); break; case Field: updateSeismoProject.Field = keyValuePair.Text.ToString(); break; case Pad: updateSeismoProject.Pad = keyValuePair.Text.ToString(); break; case JobNum: updateSeismoProject.JobNum = keyValuePair.Text.ToString(); break; case AFENum: updateSeismoProject.AFENum = keyValuePair.Text.ToString(); break; case Formation: updateSeismoProject.Formation = keyValuePair.Text.ToString(); break; case County: updateSeismoProject.County = keyValuePair.Text.ToString(); break; case State: updateSeismoProject.State = keyValuePair.Text.ToString(); break; case StartDate: updateSeismoProject.StartDate = (DateTime)keyValuePair.Text; break; case EndDate: updateSeismoProject.EndDate = (DateTime)keyValuePair.Text; break; case LastModified: updateSeismoProject.LastModified = (DateTime)keyValuePair.Text; break; case LastModifiedBy: updateSeismoProject.LastModifiedBy = keyValuePair.Text.ToString(); break; } } if (bNew) { seismosContext.SeismosProjects.Add(updateSeismoProject); } retGuid = updateSeismoProject.Id; seismosContext.SaveChanges(); } return(retGuid); }
public void AddWells(KeyValueEntity wells, Guid targetProjectId) { SeismosProject targetProject; using (var seismosContext = new seismosEntities()) { targetProject = seismosContext.SeismosProjects.FirstOrDefault(sp => sp.Id == targetProjectId); if (targetProject == null) { return; } var currWells = targetProject.Wells.ToList(); foreach (var wellsKeyValuePair in wells.KeyValuePairs) { if (wellsKeyValuePair == null) { continue; } var existingWell = currWells.FirstOrDefault(cw => cw.WellName == wellsKeyValuePair.Id); if (existingWell != null) { continue; } if (!Int32.TryParse(wellsKeyValuePair.Text.ToString(), out var iStagesToCreate)) { iStagesToCreate = 0; } var insertWell = new Well { Id = Guid.NewGuid(), WellName = wellsKeyValuePair.Id, SeismosProject = targetProject }; var hfTreatment = new HydraulicFracturingTreatment() { Id = Guid.NewGuid(), Name = insertWell.WellName + " HF", Type = TreatmentTypeEnum.HydraulicFracturing, Stages = new List <Stage>() }; for (int index = 0; index < iStagesToCreate; index++) { hfTreatment.Stages.Add(new Stage() { Id = Guid.NewGuid(), Number = index, StartTime = DateTime.Now, StopTime = DateTime.Now }); } insertWell.Treatments.Add(hfTreatment); seismosContext.Wells.Add(insertWell); } seismosContext.SaveChanges(); } }