read url from app.config
This commit is contained in:
@@ -59,6 +59,7 @@
|
||||
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.V4.Adapter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Spatial, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Spatial.5.8.4\lib\net40\System.Spatial.dll</HintPath>
|
||||
|
||||
@@ -3,38 +3,40 @@ using API.Models;
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace API.Client {
|
||||
public class Client {
|
||||
private static string url = ConfigurationManager.AppSettings["url"] + "/odata";
|
||||
|
||||
public async Task<IEnumerable<Song>> Get() {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var client = new ODataClient(url).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 client = new ODataClient(url).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 client = new ODataClient(url).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 client = new ODataClient(url).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 client = new ODataClient(url).For<Song>();
|
||||
var count = await client.Key(id).DeleteEntriesAsync();
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user