public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle instruments) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); WaterQualityDET det = new WaterQualityDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + instruments.PrincipalOrgId.Identity.ToString(); int ct = 0; foreach (BundleElement cur in sites.Elements) { SiteDTO tmp = new SiteDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Sites.Add(tmp); ct++; } if (ct > 0) //has to be elements in the collection { ct = 0; foreach (BundleElement cur in instruments.Elements) { InstrumentDTO tmp = new InstrumentDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Instruments.Add(tmp); ct++; } if (ct > 0) { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelWaterQualityDET excel = new ExcelWaterQualityDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } return(null); }
public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, bool isPrivate) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); VegDET det = new VegDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + plotTypes.PrincipalOrgId.Identity.ToString(); int ct = 0; foreach (BundleElement cur in sites.Elements) { SiteDTO tmp = new SiteDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Sites.Add(tmp); ct++; } if (ct > 0) //has to be elements in the collection { ct = 0; foreach (BundleElement cur in plotTypes.Elements) { PlotTypeDTO tmp = new PlotTypeDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.PlotTypes.Add(tmp); ct++; } if (ct > 0) { ct = 0; foreach (BundleElement cur in shrubSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.ShrubSpecies.Add(tmp); ct++; } if (treeSpecies != null) { foreach (BundleElement cur in treeSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.TreeSpecies.Add(tmp); ct++; } } if (herbSpecies != null) { foreach (BundleElement cur in herbSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.HerbSpecies.Add(tmp); ct++; } } if (nonLiving != null) { foreach (BundleElement cur in nonLiving.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.NonLiving.Add(tmp); } } if (ct > 0) //have to have at least one of herb, tree, shrub to POSSIBLY be valid { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelVegDET excel = new ExcelVegDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } } return(null); }