public static async Task<MessageWithStatus> Actions(IDbConnection connection, IQuery queries, int id, FeatureActions[] actions, string table) { if (actions == null) { return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = true }); } table = table.ToUpper(); if (table != "POLY") { return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = true }); } foreach (var polyAction in actions) { // insert top level action var actionIds = await queries.ActionQueryAsync(connection, new { id, action = polyAction.Action }); var actionId = actionIds.FirstOrDefault(); if (!actionId.HasValue) { return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = false, Status = HttpStatusCode.InternalServerError, Message = "Problem getting scope identity from actions insert." }); } // insert second level treatment foreach (var treatment in polyAction.Treatments) { var treatmentIds = await queries.TreatmentQueryAsync(connection, new { id = actionId, treatment = treatment.Treatment }); var treatmentId = treatmentIds.FirstOrDefault(); if (!treatmentId.HasValue) { return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = false, Status = HttpStatusCode.InternalServerError, Message = "Problem getting scope identity from treatment insert." }); } // move on if no herbicides if (treatment.Herbicides == null) { continue; } // insert third level herbicide foreach (var herbicide in treatment.Herbicides) { await queries.ExecuteAsync(connection, "Herbicide", new { id = treatmentId, herbicide }); } } } return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = true }); }
public bool ValidWithNoFeatureActions(string table, string type, FeatureActions[] actions) { return _validator.ValidAttributesFor(table, type, actions); }
public bool InvalidWithoutActionAndTreatment(string table, string type, FeatureActions[] actions) { return _validator.ValidAttributesFor(table, type, actions); }
public static async Task<MessageWithStatus> SpatialRow(IDbConnection connection, IQuery queries, int id, FeatureActions[] actions, char retreatment, SqlGeometry geometry, string table, double size) { if (table == "POLY") { await connection.ExecuteAsync("UPDATE [dbo].[POLY]" + "SET [Shape] = @shape," + "[AreaSqMeters] = @size," + "[Retreatment] = @retreatment " + "WHERE [FeatureID] = @featureId", new { shape = geometry, retreatment, featureId = id, size }); return await Task.Factory.StartNew(() => new MessageWithStatus { Successful = true }); } var action = actions.FirstOrDefault(); if (action == null) { return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = false, Message = "Count not find action attributes." }); } if (table == "LINE") { await connection.ExecuteAsync(string.Format("UPDATE [dbo].[{0}]", table) + "SET [FeatureSubTypeDescription] = @subtype," + "[FeatureSubTypeID] = (SELECT [FeatureSubTypeID] FROM [dbo].[LU_FEATURESUBTYPE] WHERE [FeatureSubTypeDescription] = @subType)," + "[ActionDescription] = @action," + "[ActionID] = (SELECT [ActionID] FROM [dbo].[LU_ACTION] WHERE [ActionDescription] = @action)," + "[Description] = @description," + "[LengthLnMeters] = @size," + "[Shape] = @shape " + "WHERE [FeatureID] = @featureId", new { subType = action.Type, action = action.Action, shape = geometry, size, description = action.Description, featureId = id }); } else { await connection.ExecuteAsync(string.Format("UPDATE [dbo].[{0}]", table) + "SET [FeatureSubTypeDescription] = @subtype," + "[FeatureSubTypeID] = (SELECT [FeatureSubTypeID] FROM [dbo].[LU_FEATURESUBTYPE] WHERE [FeatureSubTypeDescription] = @subType)," + "[ActionDescription] = @action," + "[ActionID] = (SELECT [ActionID] FROM [dbo].[LU_ACTION] WHERE [ActionDescription] = @action)," + "[Description] = @description," + "[Shape] = @shape " + "WHERE [FeatureID] = @featureId", new { subType = action.Type, action = action.Action, shape = geometry, description = action.Description, featureId = id }); } return await Task.Factory.StartNew(() => new MessageWithStatus() { Successful = true }); }