Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
23cf04f
начало l2
Dmitry-Ischenko Jan 27, 2021
1969eb1
подключения сервисов в контейнер сервисов
Dmitry-Ischenko Jan 30, 2021
8fa0716
добавил контроллер api для сотрудников
Dmitry-Ischenko Jan 30, 2021
03f97c9
api контроллер сотрудников
Dmitry-Ischenko Jan 30, 2021
01c2d66
Заготовка клиента Emploees
Dmitry-Ischenko Jan 30, 2021
cd4bc9d
Расширение базового клиента
Dmitry-Ischenko Jan 30, 2021
938b543
Клиент для сотрудников
Dmitry-Ischenko Jan 30, 2021
6ba7e97
подклю.чили клиент сотрудников к основному проекту
Dmitry-Ischenko Jan 30, 2021
11ef003
Добавил возможность получения бренда и категорнии по id
Dmitry-Ischenko Jan 30, 2021
74aedb9
реализовал методы интерфейса для получения категоирии и бренда по id
Dmitry-Ischenko Jan 30, 2021
3698f45
контроллер для товаров
Dmitry-Ischenko Jan 30, 2021
4e47dad
рефакт
Dmitry-Ischenko Jan 30, 2021
b0f8dd9
Описал DTO
Dmitry-Ischenko Jan 30, 2021
fabbb8f
net5
Dmitry-Ischenko Jan 30, 2021
47b2861
описал DTO
Dmitry-Ischenko Jan 30, 2021
56f0c4a
интерфейс DTO
Dmitry-Ischenko Jan 30, 2021
9e8ac34
mapping
Dmitry-Ischenko Jan 30, 2021
3ebd6ad
поменяли интерфейс на DTO
Dmitry-Ischenko Feb 3, 2021
b89c68e
подключили клиент продуктов к основному проекту
Dmitry-Ischenko Feb 3, 2021
bac6c60
запилили заказы
Dmitry-Ischenko Feb 3, 2021
370adc1
добавил профиль пользователя
Dmitry-Ischenko Feb 3, 2021
f133052
начало
Dmitry-Ischenko Jan 30, 2021
16f4b5f
Модели DTO для identity
Dmitry-Ischenko Feb 7, 2021
1097f9f
интерфейсы для Identity
Dmitry-Ischenko Feb 7, 2021
3f9e2dd
Добавил использование статичных адресов из класса WEBApi
Dmitry-Ischenko Feb 7, 2021
fb5c276
Контроллеры WebAPI для identity
Dmitry-Ischenko Feb 7, 2021
d87cca8
клиенты identity для WEBApi
Dmitry-Ischenko Feb 7, 2021
8c859b7
отключили базу данных из UI клиента
Dmitry-Ischenko Feb 7, 2021
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
21 changes: 21 additions & 0 deletions Common/WebStore.Domain/DTO/Identity/ClaimDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Security.Claims;

namespace WebStore.Domain.DTO.Identity
{
public abstract class ClaimDTO : UserDTO
{
public IEnumerable<Claim> Claims { get; set; }
}

public class AddClaimDTO : ClaimDTO { }

public class RemoveClaimDTO : ClaimDTO { }

public class ReplaceClaimDTO : UserDTO
{
public Claim Claim { get; set; }

public Claim NewClaim { get; set; }
}
}
26 changes: 26 additions & 0 deletions Common/WebStore.Domain/DTO/Identity/UserDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Microsoft.AspNetCore.Identity;
using WebStore.Domain.Entities.Identity;

namespace WebStore.Domain.DTO.Identity
{
public abstract class UserDTO
{
public User User { get; set; }
}

public class AddLoginDTO : UserDTO
{
public UserLoginInfo UserLoginInfo { get; set; }
}

public class PasswordHashDTO : UserDTO
{
public string Hash { get; set; }
}

public class SetLockoutDTO : UserDTO
{
public DateTimeOffset? LockoutEnd { get; set; }
}
}
18 changes: 18 additions & 0 deletions Common/WebStore.Domain/DTO/Orders/OrderDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using WebStore.Domain.ViewModels;

namespace WebStore.Domain.DTO.Orders
{
public record OrderItemDTO(int Id, decimal Price, int Quantity);

public record OrderDTO(
int Id,
string Name,
string Phone,
string Address,
DateTime Date,
IEnumerable<OrderItemDTO> Items);

public record CreateOrderModel(OrderViewModel Order, IList<OrderItemDTO> Items);
}
16 changes: 16 additions & 0 deletions Common/WebStore.Domain/DTO/Products/BrandDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebStore.Domain.Entities.Base;

namespace WebStore.Domain.DTO.Products
{
public class BrandDTO: NamedEntity
{
public int Order { get; set; }

public int ProductsCount { get; set; }
}
}
19 changes: 19 additions & 0 deletions Common/WebStore.Domain/DTO/Products/CategoryDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebStore.Domain.Entities.Base;

namespace WebStore.Domain.DTO.Products
{
public class CategoryDTO: NamedEntity
{

public int Order { get; set; }

public int? ParentId { get; set; }

public int ProductsCount { get; set; }
}
}
21 changes: 21 additions & 0 deletions Common/WebStore.Domain/DTO/Products/ProductDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebStore.Domain.Entities.Base;

namespace WebStore.Domain.DTO.Products
{
public class ProductDTO: NamedEntity
{
public int Order { get; set; }
public decimal Price { get; set; }
public string ImageUrl { get; set; }
public BrandDTO Brand { get; set; }
public CategoryDTO Category { get; set; }
public string Description { get; set; }
public int Discount { get; set; }

}
}
20 changes: 20 additions & 0 deletions Common/WebStore.Domain/ViewModels/UserOrderViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;

namespace WebStore.Domain.ViewModels
{
public class UserOrderViewModel
{
public int Id { get; set; }

[Required]
public string Name { get; set; }

[Required]
public string Phone { get; set; }

[Required]
public string Address { get; set; }

public decimal TotalSum { get; set; }
}
}
4 changes: 2 additions & 2 deletions Common/WebStore.Domain/WebStore.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
45 changes: 44 additions & 1 deletion Services/WebStore.Client/Base/BaseClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;

namespace WebStore.Client.Base
{
public abstract class BaseClient
public abstract class BaseClient : IDisposable
{
protected string Address { get; }
protected HttpClient Http { get; }
Expand All @@ -22,5 +24,46 @@ protected BaseClient(IConfiguration Configuration, string ServiceAddress)
}
};
}

protected T Get<T>(string url) => GetAsync<T>(url).Result;
protected async Task<T> GetAsync<T>(string url, CancellationToken Cancel = default)
{
var response = await Http.GetAsync(url, Cancel);
return await response.EnsureSuccessStatusCode().Content.ReadAsAsync<T>(Cancel);
}

protected HttpResponseMessage Post<T>(string url, T item) => PostAsync(url, item).Result;
protected async Task<HttpResponseMessage> PostAsync<T>(string url, T item, CancellationToken Cancel = default)
{
var response = await Http.PostAsJsonAsync(url, item, Cancel);
return response.EnsureSuccessStatusCode();
}

protected HttpResponseMessage Put<T>(string url, T item) => PutAsync(url, item).Result;
protected async Task<HttpResponseMessage> PutAsync<T>(string url, T item, CancellationToken Cancel = default)
{
var response = await Http.PutAsJsonAsync(url, item, Cancel);
return response.EnsureSuccessStatusCode();
}

protected HttpResponseMessage Delete(string url) => DeleteAsync(url).Result;
protected async Task<HttpResponseMessage> DeleteAsync(string url, CancellationToken Cancel = default)
{
var response = await Http.DeleteAsync(url, Cancel);
return response;
}

public void Dispose() => Dispose(true);

protected virtual void Dispose(bool Disposing)
{
if (Disposing)
{
// освобождение управляемых ресурсов
Http.Dispose();
}

// освобождение неуправляемых ресурсов
}
}
}
37 changes: 37 additions & 0 deletions Services/WebStore.Client/Employees/EmployeesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using Webstore.Interfaces;
using Webstore.Interfaces.Services;
using WebStore.Client.Base;
using WebStore.Domain.Models;

namespace WebStore.Client.Employees
{
public class EmployeesClient: BaseClient, IEmployeesData
{
private readonly ILogger<EmployeesClient> _Logger;

public EmployeesClient(IConfiguration Configuration, ILogger<EmployeesClient> Logger): base(Configuration, WebAPI.Employees)
{
_Logger = Logger;
}

public int Add(Employee employee)=>Post(Address,employee).Content.ReadAsAsync<int>().Result;

public bool Delete(int id) => Delete($"{Address}/{id}").IsSuccessStatusCode;

public IEnumerable<Employee> Get() => Get<IEnumerable<Employee>>(Address);

public Employee Get(int id) => Get<Employee>($"{Address}/{id}");

public void Update(Employee employee)
{
_Logger.LogInformation("Редактирование сотрудника с id:{ 0}", employee.Id);
Put(Address, employee);
}
}
}
32 changes: 32 additions & 0 deletions Services/WebStore.Client/Identity/IdentityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using WebStore.Domain.Entities.Identity;

namespace WebStore.Clients.Identity
{
public static class IdentityExtensions
{
public static IServiceCollection AddIdentityWebStoreWebAPIClients(this IServiceCollection services)
{
services
.AddTransient<IUserStore<User>, UsersClient>()
.AddTransient<IUserRoleStore<User>, UsersClient>()
.AddTransient<IUserPasswordStore<User>, UsersClient>()
.AddTransient<IUserEmailStore<User>, UsersClient>()
.AddTransient<IUserPhoneNumberStore<User>, UsersClient>()
.AddTransient<IUserTwoFactorStore<User>, UsersClient>()
.AddTransient<IUserClaimStore<User>, UsersClient>()
.AddTransient<IUserLoginStore<User>, UsersClient>();

services.AddTransient<IRoleStore<Role>, RolesClient>();

return services;
}

public static IdentityBuilder AddIdentityWebStoreWebAPIClients(this IdentityBuilder builder)
{
builder.Services.AddIdentityWebStoreWebAPIClients();
return builder;
}
}
}
77 changes: 77 additions & 0 deletions Services/WebStore.Client/Identity/RolesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Webstore.Interfaces;
using WebStore.Client.Base;
using WebStore.Domain.Entities.Identity;
using WebStore.Interfaces.Services.Identity;

namespace WebStore.Clients.Identity
{
public class RolesClient : BaseClient, IRolesClient
{
public RolesClient(IConfiguration Configuration) : base(Configuration, WebAPI.Identity.Role) { }

#region IRoleStore<Role>

public async Task<IdentityResult> CreateAsync(Role role, CancellationToken cancel) =>
await (await PostAsync(Address, role, cancel).ConfigureAwait(false))
.Content
.ReadAsAsync<bool>(cancel)
? IdentityResult.Success
: IdentityResult.Failed();

public async Task<IdentityResult> UpdateAsync(Role role, CancellationToken cancel) =>
await (await PutAsync(Address, role, cancel).ConfigureAwait(false))
.Content
.ReadAsAsync<bool>(cancel)
? IdentityResult.Success
: IdentityResult.Failed();

public async Task<IdentityResult> DeleteAsync(Role role, CancellationToken cancel) =>
await (await PostAsync($"{Address}/Delete", role, cancel).ConfigureAwait(false))
.Content
.ReadAsAsync<bool>(cancel)
? IdentityResult.Success
: IdentityResult.Failed();

public async Task<string> GetRoleIdAsync(Role role, CancellationToken cancel) =>
await (await PostAsync($"{Address}/GetRoleId", role, cancel).ConfigureAwait(false))
.Content
.ReadAsAsync<string>(cancel);

public async Task<string> GetRoleNameAsync(Role role, CancellationToken cancel) =>
await (await PostAsync($"{Address}/GetRoleName", role, cancel).ConfigureAwait(false))
.Content
.ReadAsAsync<string>(cancel);

public async Task SetRoleNameAsync(Role role, string name, CancellationToken cancel)
{
var response = await PostAsync($"{Address}/SetRoleName/{name}", role, cancel).ConfigureAwait(false);
role.Name = await response.Content.ReadAsAsync<string>(cancel);
}

public async Task<string> GetNormalizedRoleNameAsync(Role role, CancellationToken cancel) =>
await (await PostAsync($"{Address}/GetNormalizedRoleName", role, cancel).ConfigureAwait(false))
.Content
.ReadAsAsync<string>(cancel);

public async Task SetNormalizedRoleNameAsync(Role role, string name, CancellationToken cancel)
{
var response = await PostAsync($"{Address}/SetNormalizedRoleName/{name}", role, cancel).ConfigureAwait(false);
role.NormalizedName = await response.Content.ReadAsAsync<string>(cancel);
}

public async Task<Role> FindByIdAsync(string id, CancellationToken cancel) =>
await GetAsync<Role>($"{Address}/FindById/{id}", cancel)
.ConfigureAwait(false);

public async Task<Role> FindByNameAsync(string name, CancellationToken cancel) =>
await GetAsync<Role>($"{Address}/FindByName/{name}", cancel)
.ConfigureAwait(false);

#endregion
}
}
Loading