当前位置: 首页>>代码示例>>C#>>正文


C# IQuery.ExecuteAsync方法代码示例

本文整理汇总了C#中IQuery.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IQuery.ExecuteAsync方法的具体用法?C# IQuery.ExecuteAsync怎么用?C# IQuery.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IQuery的用法示例。


在下文中一共展示了IQuery.ExecuteAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProjectStats

        public static async Task<bool> ProjectStats(IDbConnection connection, IQuery queries, int id)
        {
            await queries.ExecuteAsync(connection, "ProjectSpatial", new
            {
                id,
                terrestrial = "terrestrial treatment area",
                aquatic = "aquatic/riparian treatment area",
                affected = "affected area",
                easement = "easement/acquisition"
            });

            return await Task.Factory.StartNew(() => true);
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:13,代码来源:Update.cs

示例2: HistoricalModule

        public HistoricalModule(IQuery queries, ISoeService soeService)
            : base("/historical/project/{id:int}")
        {
            Put["/create-related-data", true] = async (_, ctx) =>
            {
                var id = int.Parse(_.id);

                var ten = TimeSpan.FromSeconds(600);

                var db = await queries.OpenConnection();
                using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, ten, TransactionScopeAsyncFlowOption.Enabled))
                using (var connection = db.Connection)
                {
                    if (!db.Open)
                    {
                        return Negotiate.WithReasonPhrase("Database Error")
                            .WithStatusCode(HttpStatusCode.InternalServerError)
                            .WithModel("Unable to connect to the database.");
                    }

                    var projects = await queries.ProjectMinimalQueryAsync(connection, new {id = (int) id});
                    var project = projects.FirstOrDefault();

                    // make sure project id is valid
                    if (project == null)
                    {
                        return Negotiate.WithReasonPhrase("Project not found")
                            .WithStatusCode(HttpStatusCode.BadRequest)
                            .WithModel("Project not found.");
                    }

                    const string geometryQuery =
                        "SELECT [Shape] shape, [FeatureId], [TypeDescription] category FROM {0} WHERE [Project_ID] = @id";

                    foreach (var table in new[] {"POINT", "LINE", "POLY"})
                    {
                        var query = string.Format(geometryQuery, table);
                        var features = await connection.QueryAsync<SpatialFeatureSimple>(query, new
                        {
                            id = (int) id
                        });

                        foreach (var feature in features)
                        {
                            var soeAreaAndLengthResponse = await soeService.QueryAreasAndLengthsAsync(feature.Shape);

                            // handle error from soe
                            if (!soeAreaAndLengthResponse.IsSuccessful)
                            {
                                return Negotiate.WithReasonPhrase(soeAreaAndLengthResponse.Error.Message)
                                    .WithStatusCode(HttpStatusCode.InternalServerError)
                                    .WithModel(soeAreaAndLengthResponse.Error.Message);
                            }

                            var size = soeAreaAndLengthResponse.Result.Size;
                            if (table == "POLY")
                            {
                                await connection.ExecuteAsync("UPDATE [dbo].[POLY]" +
                                                              "SET [AreaSqMeters] = @size " +
                                                              "WHERE [FeatureID] = @featureId", new
                                                              {
                                                                  size,
                                                                  featureId = feature.FeatureId
                                                              });
                            }
                            else if (table == "LINE")
                            {
                                await connection.ExecuteAsync("UPDATE [dbo].[LINE]" +
                                                              "SET [LengthLnMeters] = @size " +
                                                              "WHERE [FeatureID] = @featureId", new
                                                              {
                                                                  size,
                                                                  featureId = feature.FeatureId
                                                              });
                            }

                            var soeResponse = await soeService.QueryIntersectionsAsync(feature.Shape, feature.Category);

                            // handle error from soe
                            if (!soeResponse.IsSuccessful)
                            {
                                return Negotiate.WithReasonPhrase(soeResponse.Error.Message)
                                    .WithStatusCode(HttpStatusCode.InternalServerError)
                                    .WithModel(soeResponse.Error.Message);
                            }

                            var attributes = soeResponse.Result.Attributes;

                            // insert related tables
                            var featureClass = table;
                            var primaryKey = feature.FeatureId;

                            await connection.ExecuteAsync("delete from [wri].[dbo].county WHERE [featureId] = @id;" +
                                                          "delete from [wri].[dbo].FOCUSAREA WHERE [featureId] = @id;" +
                                                          "delete from [wri].[dbo].sgma WHERE [featureId] = @id;" +
                                                          "delete from [wri].[dbo].LANDOWNER WHERE [featureId] = @id",
                                new
                                {
                                    id = primaryKey
                                });
//.........这里部分代码省略.........
开发者ID:agrc,项目名称:wri-webapi,代码行数:101,代码来源:HistoricalModule.cs

示例3: Actions

        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
            });
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:85,代码来源:Create.cs

示例4: ExtractedGis

        public static async Task<bool> ExtractedGis(IDbConnection connection, IQuery queries,
            int id, int primaryKey, IDictionary<string, IList<IntersectAttributes>> attributes, string table)
        {
            // insert related tables
            if (attributes.ContainsKey("watershedRestoration_FocusAreas"))
            {
                var data = attributes["watershedRestoration_FocusAreas"].SelectMany(x => x.Attributes,
                    (original, value) => new
                    {
                        intersect = original.Intersect,
                        region = value,
                        featureClass = table,
                        id = primaryKey
                    });

                await queries.ExecuteAsync(connection, "watershedRestoration_FocusAreas", data);
            }

            if (attributes.ContainsKey("landOwnership"))
            {
                var data = attributes["landOwnership"].Select(x => new
                {
                    intersect = x.Intersect,
                    owner = x.Attributes.First(),
                    admin = x.Attributes.Last(),
                    featureClass = table,
                    id = primaryKey
                });

                await queries.ExecuteAsync(connection, "landOwnership", data);
            }

            if (attributes.ContainsKey("sageGrouseManagementAreas"))
            {
                var data = attributes["sageGrouseManagementAreas"].SelectMany(x => x.Attributes,
                    (original, value) => new
                    {
                        intersect = original.Intersect,
                        sgma = value,
                        featureClass = table,
                        id = primaryKey
                    });

                await queries.ExecuteAsync(connection, "sageGrouseManagementAreas", data);
            }

            if (attributes.ContainsKey("counties"))
            {
                var data = attributes["counties"].SelectMany(x => x.Attributes, (original, value) => new
                {
                    intersect = original.Intersect,
                    county = value,
                    featureClass = table,
                    id = primaryKey
                });

                await queries.ExecuteAsync(connection, "counties", data);
            }

            if (attributes.ContainsKey("streamsNHDHighRes"))
            {
                var data = attributes["streamsNHDHighRes"].SelectMany(x => x.Attributes,
                    (original, value) => new
                    {
                        id,
                        featureId = primaryKey,
                        intersect = original.Intersect,
                        description = value
                    });

                await queries.ExecuteAsync(connection, "streamsNHDHighRes", data);
            }

            return await Task.Factory.StartNew((() => true));
        }
开发者ID:agrc,项目名称:wri-webapi,代码行数:75,代码来源:Create.cs


注:本文中的IQuery.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。