public void InsertTargetMaterial(TargetMaterial material) { if (material.Name == null) { throw new DALInfoNotSpecifiedException("Material name was not specified"); } using (var db = new TSPDSContext()) { var query = from m in db.TargetMaterial where m.Name.ToLower() == material.Name.ToLower() select m; if (query.Any()) { throw new DALAlreadyExistsException("Material already excist"); } db.TargetMaterial.Add(material); db.SaveChanges(); } }
public void InsertDataset(List<DataPoint> dataPoints, TargetMaterial impactMaterial, Projectile projectile, Dataformat orginalDataformat, Dataformat converteDataformat, Revision rev, User user, Revision prevRevision = null, ArticleReferences AR = null, Method method = null, StateOfAggregation stateOfAggregation = null) { if (impactMaterial.Id == 0) throw new DALInfoNotSpecifiedException("impactmaterial id was not specified"); if (projectile.Id == 0) throw new DALInfoNotSpecifiedException("Projectile id was not specified"); if (AR != null) { if (AR.Id == 0) throw new DALInfoNotSpecifiedException("ArtivleReference id was not specified"); } if (method != null) { if (method.Id == 0) throw new DALInfoNotSpecifiedException("Method id was not specified"); } if (stateOfAggregation != null) { if (stateOfAggregation.Id == 0) { throw new DALInfoNotSpecifiedException("State Of Aggregation Id was not specified"); } } foreach (var item in dataPoints) { if (item.ConvertetData == null) { throw new DALInfoNotSpecifiedException( "One or more DataPoints had unspecificed converted data"); } if (item.EqEnergy == null) { throw new DALInfoNotSpecifiedException("One or more DataPoints had unspecificed eqEnergy"); } if (item.StoppingPower == null) { throw new DALInfoNotSpecifiedException("One or more DataPoints had unspecificed StoppingPower"); } } var tempCollection = new List<ArticleReferences>(); tempCollection.Add(AR); var dataset = new Dataset() { Projectile_Id = projectile.Id, TargetMaterial_Id = impactMaterial.Id, ArticleReferences = AR, Projectile = projectile, Method = method, StateOfAggregation = stateOfAggregation, TargetMaterial = impactMaterial, }; if (AR != null) dataset.ArticleReferences_Id = AR.Id; if (method != null) dataset.Method_Id = method.Id; if (stateOfAggregation != null) dataset.StateOfAggregation_Id = stateOfAggregation.Id; using (var db = new TSPDSContext()) { db.Entry(dataset).State = EntityState.Modified; db.Dataset.Add(dataset); db.SaveChanges(); } InsertDataPoint(dataPoints, dataset, orginalDataformat, converteDataformat); InsertRevision(dataset, rev, user, prevRevision); }