示例#1
0
        public async Task <Route> UpdateRoute(Route routeToUpdate, CancellationToken cancellationToken)
        {
            using (DbConnection db = CreateConnection())
            {
                RouteDb routeToUpdateDb = RouteDb.FromDomain(routeToUpdate);

                var routeDb = await db.QuerySingleOrDefaultAsync <RouteDb>(
                    new CommandDefinition(
                        @"
                        UPDATE ""Routes"" SET 
                            ""Name"" = @name,
                            ""Points"" = @points :: json,
                            ""LastModificationDate"" = now() at time zone 'utc'
                        WHERE ""Id"" = @route_id AND ""LastModificationDate"" = @last_modification_date
                        RETURNING
                            ""Id"",
                            ""Name"",
                            ""LastModificationDate"",
                            ""Points""
",
                        new
                {
                    route_id = routeToUpdateDb.Id,
                    name = routeToUpdateDb.Name,
                    points = routeToUpdateDb.Points,
                    last_modification_date = routeToUpdateDb.LastModificationDate
                },
                        cancellationToken : cancellationToken));

                if (routeDb == null)
                {
                    throw new DBConcurrencyException();
                }

                return(RouteDb.ToDomain(routeDb));
            }
        }
示例#2
0
        public async Task <Route> GetRoute(long routeId, CancellationToken cancellationToken)
        {
            using (DbConnection db = CreateConnection())
            {
                var routeDb = await db.QuerySingleOrDefaultAsync <RouteDb>(
                    new CommandDefinition(
                        @"
                        SELECT 
                            ""Id"",
                            ""Name"",
                            ""LastModificationDate"",
                            ""Points""
                        FROM ""Routes""
                        WHERE ""Id"" = @route_id
",
                        new
                {
                    route_id = routeId
                },
                        cancellationToken : cancellationToken));

                return(RouteDb.ToDomain(routeDb));
            }
        }