コード例 #1
0
        public async Task <object> Get()
        {
            using (var dbGraphContext = new DbGraphContext(_options))
            {
                var nodes = await dbGraphContext.Nodes.ToListAsync();

                return(new { Nodes = nodes.Select(n => new
                                                  { Coordinates = new { n.Latitude, n.Longitude } }) });
            }
        }
コード例 #2
0
        public async Task <int> Post([FromBody] CoordinatesArg arg)
        {
            _log.Information("create node {coordinates}", arg);
            using (var dbGraphContext = new DbGraphContext(_options))
            {
                var node = new DbNode {
                    Latitude = arg.Latitude, Longitude = arg.Longitude
                };
                dbGraphContext.Add(node);
                await dbGraphContext.SaveChangesAsync();

                return(node.Id);
            }
        }
コード例 #3
0
        private static DbContextOptions <DbGraphContext> GetOptions()
        {
            var inMemorySqlite = new SqliteConnection("Data Source=:memory:");

            inMemorySqlite.Open();
            var optionsBuilder = new DbContextOptionsBuilder <DbGraphContext>();

            optionsBuilder.UseSqlite(inMemorySqlite);
            var options = optionsBuilder.Options;

            using (var ctx = new DbGraphContext(options))
                ctx.Database.EnsureCreated();
            return(options);
        }
コード例 #4
0
        public async Task <int> Put(int id, [FromBody] ClientNode dto)
        {
            _log.Information("change node with {id}", id);
            using (var dbGraphContext = new DbGraphContext(_options))
            {
                var node = dbGraphContext.Nodes.First(n => n.Id == id);
                node.Title     = dto.Title;
                node.Latitude  = dto.Coors.Latitude;
                node.Longitude = dto.Coors.Longitude;
                await dbGraphContext.SaveChangesAsync();

                return(200);
            }
        }
コード例 #5
0
        public async Task <IHttpActionResult> Put(int id, [FromBody] NodeArg arg)
        {
            _log.Information("change node with {id}", id);
            using (var db = new DbGraphContext(_options))
            {
                var node = await db.Nodes.SingleOrDefaultAsync(n => n.Id == id);

                if (node == null)
                {
                    return(BadRequest("node is not found"));
                }
                node.Title     = arg.Title;
                node.Latitude  = arg.Coordinates.Latitude;
                node.Longitude = arg.Coordinates.Longitude;
                await db.SaveChangesAsync();
            }
            return(Ok());
        }