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

Fix read/edition of time DateTime in extended properties #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.0" />
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="FluentValidation" Version="10.3.6" />
<PackageReference Include="FluentValidation" Version="10.4.0" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.15" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.19" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public async Task<Result<int>> Handle(ImportBrandsCommand request, CancellationT
var importedBrands = result.Data;
var errors = new List<string>();
var errorsOccurred = false;
var validatedBrands = new List<Brand>();
foreach (var brand in importedBrands)
{
var validationResult = await _addBrandValidator.ValidateAsync(_mapper.Map<AddEditBrandCommand>(brand), cancellationToken);
if (validationResult.IsValid)
{
await _unitOfWork.Repository<Brand>().AddAsync(brand);
validatedBrands.Add(brand);
}
else
{
Expand All @@ -80,6 +81,7 @@ public async Task<Result<int>> Handle(ImportBrandsCommand request, CancellationT
return await Result<int>.FailAsync(errors);
}

await _unitOfWork.Repository<Brand>().AddRangeAsync(validatedBrands.ToArray());
await _unitOfWork.CommitAndRemoveCache(cancellationToken, ApplicationConstants.Cache.GetAllBrandsCacheKey);
return await Result<int>.SuccessAsync(result.Data.Count(), result.Messages[0]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#nullable enable
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using BlazorHero.CleanArchitecture.Application.Interfaces.Repositories;
using BlazorHero.CleanArchitecture.Domain.Contracts;
Expand All @@ -13,6 +8,11 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace BlazorHero.CleanArchitecture.Application.Features.ExtendedAttributes.Commands.AddEdit
{
Expand Down Expand Up @@ -47,6 +47,31 @@ public class AddEditExtendedAttributeCommand<TId, TEntityId, TEntity, TExtendedA
public decimal? Decimal { get; set; }

public DateTime? DateTime { get; set; }
public DateTime? Date
{
get
{
return DateTime?.Date;
}
set
{
SetDateAndTime(value, Time);
}
}

public TimeSpan? Time
{
get
{
return DateTime?.TimeOfDay;
}
set
{
SetDateAndTime(Date, value);
}
}

private void SetDateAndTime(DateTime? date, TimeSpan? time) => DateTime = date?.Date.Add(time ?? new TimeSpan(0, 0, 0));

public string? Json { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions src/Application/Interfaces/Repositories/IRepositoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IRepositoryAsync<T, in TId> where T : class, IEntity<TId>

Task<T> AddAsync(T entity);

Task AddRangeAsync(params T[] entities);

Task UpdateAsync(T entity);

Task DeleteAsync(T entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ IStringLocalizer<AddEditExtendedAttributeCommandValidatorLocalization> localizer
When(request => request.Type == EntityExtendedAttributeType.DateTime, () =>
{
RuleFor(request => request.DateTime).NotNull().WithMessage(x => string.Format(localizer["DateTime value is required using {0} type!"], x.Type.ToString()));
RuleFor(request => request.Date).NotNull().WithMessage(x => string.Format(localizer["DateTime value is required using {0} type!"], x.Type.ToString()));
});

When(request => request.Type == EntityExtendedAttributeType.Json, () =>
Expand Down
12 changes: 6 additions & 6 deletions src/Client.Infrastructure/Client.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.0" />
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="MudBlazor" Version="6.0.2" />
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
<PackageReference Include="Toolbelt.Blazor.HttpClientInterceptor" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
<PackageReference Include="MudBlazor" Version="6.0.11" />
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
<PackageReference Include="Toolbelt.Blazor.HttpClientInterceptor" Version="10.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
Expand Down
18 changes: 9 additions & 9 deletions src/Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

<ItemGroup>
<PackageReference Include="Blazored.FluentValidation" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.7" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="6.0.7" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
<PackageReference Include="MudBlazor" Version="6.0.2" />
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
<PackageReference Include="MudBlazor" Version="6.0.11" />
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 2 additions & 12 deletions src/Client/Shared/Components/AddEditExtendedAttributeModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,10 @@
else if (AddEditExtendedAttributeModel.Type == EntityExtendedAttributeType.DateTime)
{
<MudItem xs="12" md="6">
<MudDatePicker @ref="_datePicker" PickerVariant="PickerVariant.Dialog" @bind-Date="AddEditExtendedAttributeModel.DateTime" Label="@_localizer["Date"]">
<PickerActions>
<MudButton Class="mr-auto align-self-start" OnClick="@(() => _datePicker.Clear())">@_localizer["Clear"]</MudButton>
<MudButton OnClick="@(() => _datePicker.Close(false))">@_localizer["Cancel"]</MudButton>
<MudButton Color="Color.Primary" OnClick="@(() => _datePicker.Close())">@_localizer["Ok"]</MudButton>
</PickerActions>
<MudDatePicker For="@(() => AddEditExtendedAttributeModel.Date)" @ref="_datePicker" Label="@_localizer["Date"]" @bind-Date="AddEditExtendedAttributeModel.Date">
</MudDatePicker>

<MudTimePicker @ref="_timePicker" PickerVariant="PickerVariant.Dialog" Label="@_localizer["Time"]" @bind-Time="_time">
<PickerActions>
<MudButton Class="mr-auto align-self-start" OnClick="@(() => _timePicker.Clear())">@_localizer["Clear"]</MudButton>
<MudButton OnClick="@(() => _timePicker.Close(false))">@_localizer["Cancel"]</MudButton>
<MudButton Color="Color.Primary" OnClick="@(() => _timePicker.Close())">@_localizer["Ok"]</MudButton>
</PickerActions>
<MudTimePicker @ref="_timePicker" Label="@_localizer["Time"]" @bind-Time="AddEditExtendedAttributeModel.Time" Disabled="TimePickerDisabled">
</MudTimePicker>
</MudItem>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class AddEditExtendedAttributeModalLocalization
{
// for localization
}

public partial class AddEditExtendedAttributeModal<TId, TEntityId, TEntity, TExtendedAttribute>
where TEntity : AuditableEntity<TEntityId>, IEntityWithExtendedAttributes<TExtendedAttribute>, IEntity<TEntityId>
where TExtendedAttribute : AuditableEntityExtendedAttribute<TId, TEntityId, TEntity>, IEntity<TId>
Expand All @@ -34,8 +33,7 @@ public partial class AddEditExtendedAttributeModal<TId, TEntityId, TEntity, TExt

private MudDatePicker _datePicker;
private MudTimePicker _timePicker;
private TimeSpan? _time;

private bool TimePickerDisabled => AddEditExtendedAttributeModel.Date == null;
public void Cancel()
{
MudDialog.Cancel();
Expand All @@ -57,7 +55,6 @@ private async Task SaveAsync()
break;
case EntityExtendedAttributeType.DateTime:
AddEditExtendedAttributeModel.DateTime ??= new DateTime(0, 0, 0);
AddEditExtendedAttributeModel.DateTime += _time ?? new TimeSpan(0, 0, 0);
AddEditExtendedAttributeModel.Decimal = null;
AddEditExtendedAttributeModel.Text = null;
AddEditExtendedAttributeModel.Json = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<base href="/" />
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css?v=5.1.0" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<link href="css/loader.css" rel="stylesheet" />
</head>

Expand Down Expand Up @@ -68,6 +68,6 @@
<script src="js/sounds.js"></script>
<script src="js/file.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js?v=5.1.0"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions src/Infrastructure.Shared/Infrastructure.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -11,7 +11,7 @@
<ProjectReference Include="..\Application\Application.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="3.1.0" />
<PackageReference Include="MimeKit" Version="3.1.0" />
<PackageReference Include="MailKit" Version="3.3.0" />
<PackageReference Include="MimeKit" Version="3.3.0" />
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
<None Remove="Persistence\**" />
</ItemGroup>-->
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.0" />
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
<PackageReference Include="EPPlus" Version="5.8.5" />
<PackageReference Include="Hangfire.Core" Version="1.7.28" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.1" />
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
<PackageReference Include="EPPlus" Version="6.0.6" />
<PackageReference Include="Hangfire.Core" Version="1.7.30" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 5 additions & 0 deletions src/Infrastructure/Repositories/RepositoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public async Task<T> AddAsync(T entity)
return entity;
}

public async Task AddRangeAsync(params T[] entities)
{
await _dbContext.Set<T>().AddRangeAsync(entities);
}

public Task DeleteAsync(T entity)
{
_dbContext.Set<T>().Remove(entity);
Expand Down
20 changes: 7 additions & 13 deletions src/Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,25 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.6" />
<PackageReference Include="Hangfire" Version="1.7.28" />
<PackageReference Include="Hangfire" Version="1.7.30" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.16.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.7" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.7" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="6.0.7" />
</ItemGroup>

</Project>