Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and improvements #44

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Breeze.Sharp/Breeze.Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
<PackageReference Include="Microsoft.Data.Services.Client">
<Version>5.8.4</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down
20 changes: 11 additions & 9 deletions Breeze.Sharp/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Breeze.Sharp {
/// </remarks>
public class DataService : IJsonSerializable {


/// <summary>
/// Constructs a new DataService with the option to use an already configured HttpClient. If one is not provided
/// then the DataService will create one internally. In either case it will be available via the HttpClient property.
Expand Down Expand Up @@ -94,12 +94,10 @@ private void InitializeHttpClient(HttpClient httpClient) {
httpClient = DefaultHttpMessageHandler == null ? new HttpClient() : new HttpClient(DefaultHttpMessageHandler);
}
_httpClient = httpClient;
_httpClient.BaseAddress = new Uri(ServiceName);
Copy link
Author

@GioviQ GioviQ Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



// Add an Accept header for JSON format.
_httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));

}

private IDataServiceAdapter GetAdapter(string adapterName) {
Expand Down Expand Up @@ -134,7 +132,7 @@ public async Task<String> GetAsync(String resourcePath) {

public async Task<String> GetAsync(String resourcePath, CancellationToken cancellationToken) {
try {
var response = await _httpClient.GetAsync(resourcePath, cancellationToken);
var response = await _httpClient.GetAsync($"{ServiceName}{resourcePath}", cancellationToken);

cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -158,10 +156,9 @@ public async Task<String> PostAsync(String resourcePath, String json) {
// new KeyValuePair<string, string>("", "login")
// });

var response = await _httpClient.PostAsync(resourcePath, content);
var response = await _httpClient.PostAsync($"{ServiceName}{resourcePath}", content);
return await ReadResult(response);
}
catch (Exception e) {
} catch (Exception e) {
Debug.WriteLine(e);
throw;
}
Expand All @@ -171,6 +168,11 @@ private static async Task<string> ReadResult(HttpResponseMessage response) {

var result = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode) {
try {
var json = JNode.DeserializeFrom(result);
response.ReasonPhrase = json.Get<string>("Message");
} catch (Exception) { }

throw new DataServiceRequestException(response, result);
}
return result;
Expand Down Expand Up @@ -210,7 +212,7 @@ public DataServiceRequestException(HttpResponseMessage httpResponse, String resp

public String ResponseContent { get; private set; }
public HttpResponseMessage HttpResponse { get; private set; }

}

}
7 changes: 4 additions & 3 deletions Breeze.Sharp/EntityAspect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Breeze.Sharp.Core;
using Breeze.Sharp.Core;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -931,13 +931,14 @@ private bool FixupFksOnUnattached(NavigationProperty np) {
var npEntity = GetValue<IEntity>(np);
// property is already linked up
if (npEntity != null) {
if (npEntity.EntityAspect.IsDetached) {
if (npEntity.EntityAspect.IsDetached && np.ForeignKeyProperties.Any()) {
// need to insure that fk props match
var fkProps = np.ForeignKeyProperties;
npEntity.EntityAspect.EntityType = np.EntityType;
// Set this Entity's fk to match np EntityKey
// Order.CustomerID = aCustomer.CustomerID
npEntity.EntityAspect.EntityKey.Values.ForEach((v, i) => SetDpValue(fkProps[i], v));
//commented because set keys to default values
Copy link
Author

@GioviQ GioviQ Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/enkodellc/blazorboilerplate/blob/development/src/Shared/BlazorBoilerplate.Shared/Dto/Db/UserProfile.cs

ApplicationUser has wrong key as empty Guid

Probably you have a better solution. You can use that repo as test.

//npEntity.EntityAspect.EntityKey.Values.ForEach((v, i) => SetDpValue(fkProps[i], v));
}
return false;
}
Expand Down
Loading