public static JObject ToJson(FishDiet diet) { if (diet != null) { JObject o = new JObject(); o.Add(JsonUtils.Id, JsonUtils.ToJson(diet.Identity)); o.Add("fishid", JsonUtils.ToJson(diet.FishId)); o.Add("taxaid", JsonUtils.ToJson(diet.TaxaId)); if (diet.VialId != null) { o.Add("vialid", diet.VialId); } if (diet.GutSampleId != null) { o.Add("gutsampleid", diet.GutSampleId); } if (diet.LifeStage != null) { o.Add("lifestage", diet.LifeStage); } o.Add("count", diet.Count); o.Add("wholeanimalweighed", diet.WholeAnimalsWeighed); o.Add("individualmass", diet.IndividualMass); o.Add("samplemass", diet.SampleMass); if (diet.Description != null) { o.Add(JsonUtils.Description, diet.Description); } return(o); } return(null); }
public bool CanDelete(FishDiet item) { if (item != null) { return(this.CanDelete(item.FishId)); } return(false); }
public bool Delete(FishDiet item) { if (item != null && this.CanDelete(item)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteFishDiet + Db.WhereId; cmd.Parameters.AddWithValue("id", item.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public IEnumerable <FishDiet> GetFishDiet(IEnumerable <CompoundIdentity> taxaId) { if (this.CanGet()) { string wh = Db.GetWhere(taxaId, "taxasid", "taxaid"); if (wh != null && wh.Length > 0) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishDiet + Db.Where + wh; NpgsqlDataReader rdr = Db.ExecuteReader(cmd); FishDiet o = null; List <FishDiet> permissions = new List <FishDiet>(); if (rdr != null) { try { while (rdr.Read()) { o = this.dietBuilder.Build(rdr); if (o != null) { permissions.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(permissions); } } return(null); }
public IEnumerable <FishDiet> GetFishDiet(IEnumerable <Guid> fishId) { if (fishId != null && this.CanGet()) { string wh = Db.GetWhere(fishId, "\"FishId\""); if (wh != null && wh.Length > 0) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishDiet + Db.Where + wh; NpgsqlDataReader rdr = Db.ExecuteReader(cmd); FishDiet o = null; List <FishDiet> items = new List <FishDiet>(); if (rdr != null) { try { while (rdr.Read()) { o = this.dietBuilder.Build(rdr); if (o != null) { items.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(items); } } return(null); }
public IEnumerable <FishDiet> GetFishDiet(Guid fishId) { if (!Guid.Empty.Equals(fishId) && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishDiet + Db.Where + Db.WhereFishId; cmd.Parameters.AddWithValue("fid", fishId); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); FishDiet o = null; List <FishDiet> items = new List <FishDiet>(); if (rdr != null) { try { while (rdr.Read()) { o = this.dietBuilder.Build(rdr); if (o != null) { items.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(items); } return(null); }
public IEnumerable <FishDiet> GetFishDiet(CompoundIdentity taxaId) { if (this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishDiet + Db.Where + Db.WhereTaxa; Db.AddParam(cmd, "taxasid", "taxaid", taxaId); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); FishDiet o = null; List <FishDiet> items = new List <FishDiet>(); if (rdr != null) { try { while (rdr.Read()) { o = this.dietBuilder.Build(rdr); if (o != null) { items.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(items); } return(null); }
private UpdateStatus InitialLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle nets, EntityBundle fishSpecies, EntityBundle macroSpecies, FishDET curdet, ICatchEffortProvider depl, ICatchHaulProvider haul, IFishProvider fish, bool isPrivate) { UpdateStatus stat = null; if (sites == null || nets == null || fishSpecies == null || seId == null || seId.IsEmpty || macroSpecies == null) { stat = new UpdateStatus(UpdateIssue.DataIssue); stat.Add(new IssueNotice("BundlesOrEvent", "Null value")); } else { //TODO -- may need to do case insensitive ops or not -- verify how excel part is implemented Dictionary <string, CompoundIdentity> deployIds = new Dictionary <string, CompoundIdentity>(); BundleElement elem; foreach (CatchEffortDTO cur in curdet.CatchEfforts.Values) { if (cur != null && !deployIds.ContainsKey(cur.CatchId)) { elem = sites.Get(cur.SiteId); if (elem != null) { CompoundIdentity siteId = elem.EntityId; Point2 <double> tmpPoint = null; if (cur.CatchX.HasValue && cur.CatchY.HasValue) { if (!(cur.CatchX.Value.IsInfiniteOrNaN() && cur.CatchY.Value.IsInfiniteOrNaN())) { tmpPoint = GeometryFactory2Double.Instance.ConstructPoint(cur.CatchX.Value, cur.CatchY.Value); } } double dep = cur.Depth.HasValue ? cur.Depth.Value : double.NaN; double dox = cur.DO.HasValue ? cur.DO.Value : double.NaN; double pH = cur.pH.HasValue ? cur.pH.Value : double.NaN; double sal = cur.Salinity.HasValue ? cur.Salinity.Value : double.NaN; double tmp = cur.Temp.HasValue ? cur.Temp.Value : double.NaN; double vel = cur.Velocity.HasValue ? cur.Velocity.Value : double.NaN; CatchEffort cat = depl.Create(seId, siteId, cur.DateTime, cur.Comments, isPrivate, cur.CatchMethod, cur.HabitatStrata, tmpPoint, (float)dep, (float)pH, (float)tmp, (float)dox, (float)sal, (float)vel); if (cat != null) { deployIds[cur.CatchId] = cat.Identity; } else { stat = Add("Create", "Deployment", UpdateIssue.DataIssue, stat); } } else { stat = Add("SiteCode", "Empty or missing", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Empty or missing", UpdateIssue.DataIssue, stat); } } foreach (CatchMetricDTO cur in curdet.CatchMetrics.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { try { CatchMetric met = haul.CreateMetric(depId, (float)cur.Value, cur.MetricType, cur.Comments); if (met == null) { stat = Add("Create", "CatchMetric", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "CatchMetric", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in CatchMetric", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in CatchMetric", UpdateIssue.DataIssue, stat); } } foreach (NetHaulEventDTO cur in curdet.NetHaulEvents.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { elem = nets.Get(cur.NetId); if (elem != null) { CompoundIdentity netId = elem.EntityId; try { double area = cur.AreaSampled.HasValue ? cur.AreaSampled.Value : double.NaN; double vol = cur.VolumeSampled.HasValue ? cur.VolumeSampled.Value : double.NaN; NetHaulEvent met = haul.CreateHaul(depId, netId, (float)area, (float)vol, cur.Comments); if (met == null) { stat = Add("Create", "NetHaulEvent", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "NetHaulEvent", UpdateIssue.DataIssue, stat); } } else { stat = Add("NetId", "Fail to lookup in NetHaulEvent", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in NetHaulEvent", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in NetHaulEvent", UpdateIssue.DataIssue, stat); } } foreach (FishCountDTO cur in curdet.FishCounts.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { elem = fishSpecies.Get(cur.SpeciesId); if (elem != null) { CompoundIdentity fishId = elem.EntityId; try { FishCount met = haul.CreateFishCount(depId, fishId, cur.Count.HasValue?cur.Count.Value:0, cur.Comments); if (met == null) { stat = Add("Create", "FishCount", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishCount", UpdateIssue.DataIssue, stat); } } else { stat = Add("TaxaId", "Fail to lookup in FishCount", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in FishCount", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in FishCount", UpdateIssue.DataIssue, stat); } } //keep track of all fishids as we go for lookups Dictionary <string, Guid> fishIds = new Dictionary <string, Guid>(); foreach (FishDTO cur in curdet.Fish.Values) { if (cur != null && deployIds.ContainsKey(cur.CatchId)) { CompoundIdentity depId = deployIds[cur.CatchId]; if (depId != null) { elem = fishSpecies.Get(cur.SpeciesId); if (elem != null) { CompoundIdentity fishId = elem.EntityId; try { double std = cur.LengthStandard.HasValue ? cur.LengthStandard.Value : double.NaN; double frk = cur.LengthFork.HasValue ? cur.LengthFork.Value : double.NaN; double tot = cur.LengthTotal.HasValue ? cur.LengthTotal.Value : double.NaN; double wei = cur.Mass.HasValue ? cur.Mass.Value : double.NaN; Osrs.Oncor.WellKnown.Fish.Fish met = fish.CreateFish(depId, fishId, (float)std, (float)frk, (float)tot, (float)wei, cur.AdClipped, cur.CodedWireTag, cur.Comments); fishIds[cur.FishId] = met.Identity; if (met == null) { stat = Add("Create", "Fish", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "Fish", UpdateIssue.DataIssue, stat); } } else { stat = Add("TaxaId", "Fail to lookup in Fish", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in Fish", UpdateIssue.DataIssue, stat); } } else { stat = Add("CatchId", "Fail to lookup in Fish", UpdateIssue.DataIssue, stat); } } foreach (DietDTO cur in curdet.Diet.Values) { if (cur != null && fishIds.ContainsKey(cur.FishId)) { Guid depId = fishIds[cur.FishId]; if (!Guid.Empty.Equals(depId)) { elem = macroSpecies.Get(cur.SpeciesId); if (elem != null || string.IsNullOrEmpty(cur.SpeciesId)) //allow for empty gut { CompoundIdentity taxaId; if (elem != null) { taxaId = elem.EntityId; } else { taxaId = new CompoundIdentity(Guid.Empty, Guid.Empty); } try { double sam = cur.SampleMass.HasValue ? cur.SampleMass.Value : double.NaN; double ind = cur.IndividualMass.HasValue ? cur.IndividualMass.Value : double.NaN; uint? wh = null; if (cur.WholeAnimalsWeighed.HasValue) { wh = (uint)cur.WholeAnimalsWeighed.Value; } FishDiet met = null; if (taxaId.IsEmpty) { if (cur.Count == 0) //the only way its legal { met = fish.CreateFishDiet(depId, taxaId, cur.GutSampleId, cur.VialId, cur.LifeStage, cur.Count, (float)sam, (float)ind, wh, cur.Comments); } } else { met = fish.CreateFishDiet(depId, taxaId, cur.GutSampleId, cur.VialId, cur.LifeStage, cur.Count, (float)sam, (float)ind, wh, cur.Comments); } if (met == null) { stat = Add("Create", "FishDiet", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishDiet", UpdateIssue.DataIssue, stat); } } else { stat = Add("TaxaId", "Fail to lookup in FishDiet", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishDiet", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishDiet", UpdateIssue.DataIssue, stat); } } foreach (GeneticDTO cur in curdet.Genetics.Values) { if (cur != null && fishIds.ContainsKey(cur.FishId)) { Guid depId = fishIds[cur.FishId]; if (!Guid.Empty.Equals(depId)) { try { StockEstimates est = new StockEstimates(); if (!string.IsNullOrEmpty(cur.BestStockEstimate) && cur.ProbabilityBest.HasValue) { est[cur.BestStockEstimate] = (float)cur.ProbabilityBest.Value; } if (!string.IsNullOrEmpty(cur.SecondStockEstimate) && cur.ProbabilitySecondBest.HasValue) { est[cur.SecondStockEstimate] = (float)cur.ProbabilitySecondBest.Value; } if (!string.IsNullOrEmpty(cur.ThirdStockEstimate) && cur.ProbabilityThirdBest.HasValue) { est[cur.ThirdStockEstimate] = (float)cur.ProbabilityThirdBest.Value; } FishGenetics met = fish.CreateFishGenetics(depId, cur.GeneticSampleId, cur.LabSampleId, est, cur.Comments); if (met == null) { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } foreach (IdTagDTO cur in curdet.IdTags.Values) { if (cur != null && fishIds.ContainsKey(cur.FishId)) { Guid depId = fishIds[cur.FishId]; if (!Guid.Empty.Equals(depId)) { try { FishIdTag met = fish.CreateIdTag(depId, cur.TagCode, cur.TagType, cur.TagManufacturer, cur.Comments); if (met == null) { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } catch { stat = Add("Create", "FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } else { stat = Add("FishId", "Fail to lookup in FishIdTag", UpdateIssue.DataIssue, stat); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } } return(stat); }