This commit is contained in:
Nick Randolph 2021-11-15 18:50:55 +11:00
Родитель f5c29cdc47
Коммит 2b6399654b
18 изменённых файлов: 126 добавлений и 76 удалений

Просмотреть файл

@ -32,6 +32,7 @@ using Commerce.ViewModels;
using Commerce.Services;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Commerce.Models;
namespace Commerce
{

Просмотреть файл

@ -24,7 +24,12 @@
<Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Services\IProductService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\JsonDataService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Product.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\ProductServices.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Profile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Review.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Credentials.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\DealsViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Filter.cs" />
@ -36,6 +41,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ProductDetailsViewModel.g.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ProductsViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ProductsViewModel.g.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ProfileViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\CartDialog.xaml.cs">
<DependentUpon>CartDialog.xaml</DependentUpon>
</Compile>
@ -141,5 +147,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Navigation\" />
<Folder Include="$(MSBuildThisFileDirectory)Models\" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,4 +1,5 @@
using Commerce.Services;
using Commerce.Models;
using Commerce.Services;
namespace Commerce.DesignTime
{

Просмотреть файл

@ -0,0 +1,16 @@
namespace Commerce.Models;
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public string FullPrice { get; set; }
public string Price { get; set; }
public string Discount { get; set; }
public string Photo { get; set; }
public Review[] Reviews { get; set; }
}

Просмотреть файл

@ -0,0 +1,8 @@
namespace Commerce.Models;
public class Profile
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Avatar { get; set; }
}

Просмотреть файл

@ -0,0 +1,8 @@
namespace Commerce.Models;
public class Review
{
public string Photo { get; set; }
public string Name { get; set; }
public string Message { get; set; }
}

Просмотреть файл

@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Commerce.Models;
namespace Commerce.Services;
public interface IProductService
{
Task<IEnumerable<Product>> GetProducts(string? term, CancellationToken ct);
}

Просмотреть файл

@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Windows.Storage;
namespace Commerce.Services;
public class JsonDataService<TData>
{
private string DataFile { get; }
private TData[] Entities { get; set; }
public JsonDataService(string dataFile)
{
DataFile = dataFile;
}
private async Task Load()
{
if (Entities is not null)
{
return;
}
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///{DataFile}"));
using var stream = await storageFile.OpenStreamForReadAsync();
Entities = JsonSerializer.Deserialize<TData[]>(stream, new JsonSerializerOptions
{
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString,
AllowTrailingCommas = true
});
}
public async Task<TData[]> GetEntities()
{
await Load();
return Entities;
}
}

Просмотреть файл

@ -1,50 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using Commerce.Models;
namespace Commerce.Services;
public class JsonDataService<TData>
{
private string DataFile { get; }
private TData[] Entities { get; set; }
public JsonDataService(string dataFile)
{
DataFile = dataFile;
}
private async Task Load()
{
if (Entities is not null)
{
return;
}
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///{DataFile}"));
using var stream = await storageFile.OpenStreamForReadAsync();
Entities = JsonSerializer.Deserialize<TData[]>(stream, new JsonSerializerOptions
{
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString,
AllowTrailingCommas = true
});
}
public async Task<TData[]> GetEntities()
{
await Load();
return Entities;
}
}
public class ProductService : JsonDataService<Product>, IProductService
{
public ProductService(string dataFile) : base(dataFile)
@ -65,30 +28,3 @@ public class ProductService : JsonDataService<Product>, IProductService
return products;
}
}
public interface IProductService
{
Task<IEnumerable<Product>> GetProducts(string? term, CancellationToken ct);
}
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public string FullPrice { get; set; }
public string Price { get; set; }
public string Discount { get; set; }
public string Photo { get; set; }
public Review[] Reviews { get; set; }
}
public class Review
{
public string Photo { get; set; }
public string Name { get; set; }
public string Message { get; set; }
}

Просмотреть файл

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Commerce.Models;
using Commerce.Services;
using Uno.Extensions;

Просмотреть файл

@ -1,5 +1,6 @@
using System;
using System.Linq;
using Commerce.Models;
using Commerce.Services;
namespace Commerce.ViewModels;

Просмотреть файл

@ -1,5 +1,6 @@
using System.Threading;
using System.Threading.Tasks;
using Commerce.Models;
using Commerce.Services;
using Uno.Extensions.Reactive;

Просмотреть файл

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Commerce.Models;
using Commerce.Services;
using Uno.Extensions.Reactive;

Просмотреть файл

@ -3,6 +3,7 @@ using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Commerce.Models;
using Commerce.Services;
using Uno.Extensions.Reactive;

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Commerce.Models;
using Commerce.Services;
using Uno.Extensions.Reactive;
using static Commerce.ViewModels.FilterViewModel;

Просмотреть файл

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Commerce.ViewModels
{
public class ProfileViewModel
{
}
}

Просмотреть файл

@ -1,6 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0;uap10.0.18362;xamarinios10;monoandroid10.0;monoandroid11.0;net6.0-ios;net6.0-android</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;xamarinios10;monoandroid10.0;monoandroid11.0</TargetFrameworks>
<TargetFrameworks Condition="'$(UnoExtensionsDisableNet6)'==''">$(TargetFrameworks);net5.0;net6.0;uap10.0.18362;net6.0-ios;net6.0-android</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(IsUWP)' == 'true'">

Просмотреть файл

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSBuild.Sdk.Extras" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;xamarinios10;monoandroid10.0;monoandroid11.0</TargetFrameworks>
<TargetFrameworks Condition="'$(UnoExtensionsDisableNet6)'==''">$(TargetFrameworks);net5.0;net6.0;uap10.0.18362;net6.0-ios;net6.0-android</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
<ItemGroup>
<ProjectReference Include="..\Uno.Extensions.Navigation\Uno.Extensions.Navigation.csproj" />
</ItemGroup>
</Project>