public bool CanDelete(CatchMetric item) { if (item != null) { if (this.helperProvider == null) { this.helperProvider = new PgCatchEffortProvider(this.Context); } return(this.helperProvider.CanDelete(item.CatchEffortId)); } return(false); }
public static JObject ToJson(CatchMetric metric) { if (metric != null) { JObject o = new JObject(); o.Add(JsonUtils.Id, JsonUtils.ToJson(metric.Identity)); o.Add("catcheffortid", JsonUtils.ToJson(metric.CatchEffortId)); o.Add("metrictype", metric.MetricType); o.Add("value", metric.Value); if (metric.Description != null) { o.Add(JsonUtils.Description, metric.Description); } return(o); } return(null); }
public bool Delete(CatchMetric item) { if (item != null && this.CanDelete(item)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteFishCatchMetrics + Db.WhereId; cmd.Parameters.AddWithValue("id", item.Identity); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public IEnumerable <CatchMetric> GetMetrics(CompoundIdentity catchEffortId, string metricType) { if (!catchEffortId.IsNullOrEmpty() && Db.DataStoreIdentity.Equals(catchEffortId.DataStoreIdentity) && this.CanGet()) { if (string.IsNullOrEmpty(metricType)) { return(new List <CatchMetric>()); //can't have any with null or empty metric type, so always an empty set } NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishCatchMetrics + Db.Where + Db.WhereEffort + " AND " + Db.GetWhere("MetricType", "metric", StringComparison.OrdinalIgnoreCase); cmd.Parameters.AddWithValue("ceid", catchEffortId.Identity); cmd.Parameters.AddWithValue("metric", metricType); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); CatchMetric o = null; List <CatchMetric> permissions = new List <CatchMetric>(); if (rdr != null) { try { while (rdr.Read()) { o = this.catchBuilder.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 <CatchMetric> GetMetrics(CompoundIdentity catchEffortId) { if (!catchEffortId.IsNullOrEmpty() && Db.DataStoreIdentity.Equals(catchEffortId.DataStoreIdentity) && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectFishCatchMetrics + Db.Where + Db.WhereEffort; cmd.Parameters.AddWithValue("ceid", catchEffortId.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); CatchMetric o = null; List <CatchMetric> permissions = new List <CatchMetric>(); if (rdr != null) { try { while (rdr.Read()) { o = this.catchBuilder.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); }
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); }