creating oData client
testing odata interface
This commit is contained in:
44
API/API.Client/Client.cs
Normal file
44
API/API.Client/Client.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
using API.Models;
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace API.Client {
|
||||
public class Client {
|
||||
|
||||
public async Task<IEnumerable<Song>> Get() {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var songs = await client.FindEntriesAsync();
|
||||
return songs;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Song>> Get(Expression<Func<Song, bool>> filterExpression) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var songs = await client.Filter(filterExpression).FindEntriesAsync();
|
||||
return songs;
|
||||
}
|
||||
|
||||
public async Task<Song> Get(long id) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var song = await client.Key(id).FindEntryAsync();
|
||||
return song;
|
||||
}
|
||||
|
||||
public async Task<Song> Post(Song song) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var insertedSong = await client.Set(song).InsertEntryAsync();
|
||||
return insertedSong;
|
||||
}
|
||||
|
||||
public async Task<int> Delete(long id) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var count = await client.Key(id).DeleteEntriesAsync();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user