internal bool CanDelete(CompoundIdentity vegSurveyId) { if (this.CanDelete()) { if (!vegSurveyId.Equals(lastVegSurveyId)) { this.lastVegSurveyId = vegSurveyId; VegSurvey depl = this.GetSurvey(vegSurveyId); if (depl != null) { this.lastEditPermission = this.CanDelete(depl); } else // can't get the effort, so it will always fail { this.lastEditPermission = false; } return(this.lastEditPermission); } else { return(this.lastEditPermission); //same as last check } } return(false); }
public VegSurvey GetSurvey(CompoundIdentity id) { if (!id.IsNullOrEmpty() && Db.DataStoreIdentity.Equals(id.DataStoreIdentity) && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectSurvey + Db.Where + Db.WhereId; cmd.Parameters.AddWithValue("id", id.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); VegSurvey o = null; if (rdr != null) { try { rdr.Read(); o = this.surveyBuilder.Build(rdr); if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } } return(o); } return(null); }
//:sitesid, :siteid, :ptid, :loc, :area, :eMin, :eMax, :d, :private WHERE \"Id\"=:id"; public bool Update(VegSurvey item) { if (item != null && this.CanUpdate(item)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.UpdateSurvey; cmd.Parameters.AddWithValue("id", item.Identity.Identity); Db.AddParam(cmd, "sitesid", "siteid", item.SiteId); Db.AddParam(cmd, "ptid", item.PlotTypeId); Db.AddParam(cmd, "loc", item.Location); Db.AddParam(cmd, "area", item.Area); Db.AddParam(cmd, "eMin", "eMax", item.ElevationRange); Db.AddParam(cmd, "d", item.Description); cmd.Parameters.AddWithValue("private", item.IsPrivate); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public bool Delete(VegSurvey item) { if (item != null && this.CanDelete(item)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.DeleteSurvey; cmd.Parameters.AddWithValue("id", item.Identity.Identity); Db.ExecuteNonQuery(cmd); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("vsid", item.Identity.Identity); //used for veg samples, etc. //--items sub to fish do a where fishid in (select) cmd.CommandText = Db.DeleteHerbSample + Db.WhereVegSurveyIn; Db.ExecuteNonQuery(cmd); cmd.CommandText = Db.DeleteTreeSample + Db.WhereVegSurveyIn; Db.ExecuteNonQuery(cmd); cmd.CommandText = Db.DeleteShrubSample + Db.WhereVegSurveyIn; Db.ExecuteNonQuery(cmd); //--end all sub-items, now it's ok to remove the fish itself cmd.CommandText = Db.DeleteVegSample + Db.WhereVegSurvey; Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public static JObject ToJson(VegSurvey survey) { if (survey != null) { JObject o = new JObject(); o.Add(JsonUtils.Id, JsonUtils.ToJson(survey.Identity)); o.Add("sampleeventid", JsonUtils.ToJson(survey.SampleEventId)); o.Add("siteid", JsonUtils.ToJson(survey.SiteId)); o.Add("plottypeid", JsonUtils.ToJson(survey.PlotTypeId)); if (survey.Location != null) { o.Add("location", survey.Location.ToString()); } o.Add("area", survey.Area); if (survey.ElevationRange != null) { o.Add("elevationmin", survey.ElevationRange.Min); o.Add("elevationmax", survey.ElevationRange.Max); } if (survey.Description != null) { o.Add(JsonUtils.Description, survey.Description); } o.Add("isprivate", survey.IsPrivate); return(o); } return(null); }
public bool DeleteSurvey(CompoundIdentity id) { VegSurvey tmp = this.GetSurvey(id); if (tmp != null) { return(Delete(tmp)); } return(false); }
public bool CanDelete(VegSurvey item) { if (item != null && Db.DataStoreIdentity.Equals(item.Identity.DataStoreIdentity)) { if (this.CanDelete()) { UserProvider prov = UserAffilationSecurityManager.Instance.GetProvider(this.Context); if (prov != null) { return(prov.HasAffiliationForSampleEvent(item.SampleEventId, true)); } } } return(false); }
public IEnumerable <VegSurvey> GetForSite(CompoundIdentity siteId) { if (!siteId.IsNullOrEmpty() && this.CanGet()) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.SelectSurvey + Db.Where + Db.WhereSite; cmd.Parameters.AddWithValue("sitesid", siteId.DataStoreIdentity); cmd.Parameters.AddWithValue("siteid", siteId.Identity); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); VegSurvey o = null; List <VegSurvey> permissions = new List <VegSurvey>(); if (rdr != null) { try { while (rdr.Read()) { o = this.surveyBuilder.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); }
//\"Id\", \"VegSurveyId\", \"SiteSystemId\", \"SiteId\", \"When\", \"PointLocation\", \"ElevMin\", \"ElevMax\" public VegSample Build(DbDataReader reader) { VegSample tmp = new VegSample((Guid)reader[0], new CompoundIdentity(Db.DataStoreIdentity, DbReaderUtils.GetGuid(reader, 1)), new CompoundIdentity(DbReaderUtils.GetGuid(reader, 2), DbReaderUtils.GetGuid(reader, 3)), Db.FixDate(DbReaderUtils.GetDate(reader, 4)), Db.GetLoc(reader, 5), DbReaderUtils.GetSingle(reader, 6), DbReaderUtils.GetSingle(reader, 7)); if (!seen.Contains(tmp.VegSurveyId)) { seen.Add(tmp.VegSurveyId); VegSurvey e = this.helperBuilder.GetSurvey(tmp.VegSurveyId); if (e != null) { got.Add(tmp.VegSurveyId); } } if (!got.Contains(tmp.VegSurveyId)) { return(null); } return(tmp); }
private UpdateStatus InitialLoad(CompoundIdentity seId, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, VegDET curdet, IVegSurveyProvider depl, IVegSampleProvider meas, bool isPrivate) { UpdateStatus stat = null; if (sites == null || plotTypes == null || seId == null || seId.IsEmpty) { 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 (VegSurveyDTO cur in curdet.Surveys.Values) { if (cur != null && !deployIds.ContainsKey(cur.SurveyId)) { elem = sites.Get(cur.SiteId); if (elem != null) { CompoundIdentity siteId = elem.EntityId; if (cur.PlotTypeId != null) { elem = plotTypes.Get(cur.PlotTypeId); } else { elem = null; } if (elem != null || cur.PlotTypeId == null) { CompoundIdentity plotTypeId; if (elem != null) { plotTypeId = elem.EntityId; } else { plotTypeId = null; } Point2 <double> tmpPoint = null; if (cur.AdHocLat.HasValue && cur.AdHocLon.HasValue) { if (!(cur.AdHocLat.Value.IsInfiniteOrNaN() && cur.AdHocLon.Value.IsInfiniteOrNaN())) { tmpPoint = GeometryFactory2Double.Instance.ConstructPoint(cur.AdHocLat.Value, cur.AdHocLon.Value); } } float area = float.NaN; if (cur.Area.HasValue) { area = (float)cur.Area.Value; } float minElev = float.NaN; float maxElev = float.NaN; if (cur.MinElevation.HasValue) { minElev = (float)cur.MinElevation.Value; } else if (cur.MaxElevation.HasValue) { minElev = (float)cur.MaxElevation.Value; //lets min/max be the same when only one is provided } if (cur.MaxElevation.HasValue) { maxElev = (float)cur.MaxElevation.Value; } else { maxElev = minElev; //lets min/max be the same when only one is provided } VegSurvey dep = depl.Create(seId, siteId, plotTypeId, tmpPoint, area, minElev, maxElev, cur.Comments, isPrivate); if (dep != null) { deployIds[cur.SurveyId] = dep.Identity; } else { stat = Add("Create", "Deployment", UpdateIssue.DataIssue, stat); } } else { stat = Add("PlotType", "Empty or missing", UpdateIssue.DataIssue, stat); } } else { stat = Add("SiteCode", "Empty or missing", UpdateIssue.DataIssue, stat); } } else { stat = Add("DeployCode", "Empty or missing", UpdateIssue.DataIssue, stat); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.DataIssue); IEnumerable <VegSamplesDTO> samps = ToSamples(curdet, deployIds, sites, plotTypes, shrubSpecies, treeSpecies, herbSpecies, nonLiving); if (samps != null) { foreach (VegSamplesDTO cur in samps) { if (meas.Create(cur) == null) { stat.Add(new IssueNotice("InsertBatch", "Failed inserting a batch of measurements")); } } if (stat.Count < 1) { stat = null; } } else { stat.Add(new IssueNotice("CreateSamples", "Failed to generate sample batches from file")); } } if (stat == null) { stat = new UpdateStatus(UpdateIssue.AllOk); stat.Add(new IssueNotice("NoIssues", "No issues")); } } return(stat); }