improvements, fixes, etc...
This commit is contained in:
parent
572473d471
commit
5be059cfeb
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using AyCode.Core.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Entities.Products;
|
||||
|
||||
namespace TIAM.Database.DbSets.Products;
|
||||
|
|
@ -8,7 +9,11 @@ public static class ProductDbSetExtensions
|
|||
#region Add, Update, Remove
|
||||
|
||||
public static bool AddProduct(this IProductDbSet ctx, Product product)
|
||||
=> ctx.Products.Add(product).State == EntityState.Added;
|
||||
{
|
||||
if (product.Id.IsNullOrEmpty()) product.Id = Guid.NewGuid();
|
||||
|
||||
return ctx.Products.Add(product).State == EntityState.Added;
|
||||
}
|
||||
|
||||
public static bool UpdateProduct(this IProductDbSet ctx, Product product)
|
||||
=> ctx.Products.Update(product).State == EntityState.Modified;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using TIAM.Entities.Users;
|
|||
namespace TIAM.Entities.ServiceProviders;
|
||||
|
||||
[Table("ServiceProviders")]
|
||||
public class Company : AcCompany<User, UserToCompany, Profile, Address>, ICompany, IProductsRelation
|
||||
public class Company : AcCompany<User, UserToCompany, Profile, Address>, ICompany, IProductsRelation, IProfileRelation<Profile>
|
||||
{
|
||||
public virtual List<Product> Products { get; set; } = new();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,21 @@ using TIAM.Entities.Users;
|
|||
|
||||
namespace TIAM.Models.Dtos.Users
|
||||
{
|
||||
public class UserModelDtoDetail : AcUserModelDtoDetailBase<UserDtoDetail, Profile, Company, UserToCompany, Address>, IProductsRelation, IUserModelDtoMinBase
|
||||
public class UserModelDtoDetail : AcUserModelDtoDetailBase<UserDtoDetail, Profile, Company, UserToCompany, Address>, IProductsRelation, IUserModelDtoMinBase, IProfileForeignKey
|
||||
{
|
||||
public Guid ProfileId
|
||||
{
|
||||
get => ProfileDto.Id;
|
||||
set {}
|
||||
}
|
||||
|
||||
public List<UserProductMapping> UserProductMappings { get; set; }
|
||||
public List<Product> Products { get; set; }
|
||||
|
||||
public UserModelDtoDetail() { }
|
||||
public UserModelDtoDetail()
|
||||
{
|
||||
}
|
||||
|
||||
public UserModelDtoDetail(User user) : base(user)
|
||||
{
|
||||
if (user.Products.Count == 0) return;
|
||||
|
|
@ -40,6 +49,5 @@ namespace TIAM.Models.Dtos.Users
|
|||
//TODO: Models... - J.
|
||||
throw new NotImplementedException("CreateMainEntity");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
<DetailRowTemplate>
|
||||
<DxTabs>
|
||||
<DxTabPage Text="Profile">
|
||||
<ProfileGridComponent ProfileId="((Company)context.DataItem).ProfileId" KeyboardNavigationEnabled="true" />
|
||||
<ProfileGridComponent ParentData="((Company)context.DataItem)" KeyboardNavigationEnabled="true" />
|
||||
</DxTabPage>
|
||||
<DxTabPage Text="Products">
|
||||
<ProductDetailGridComponent ContextId="((Company)context.DataItem).Id" KeyboardNavigationEnabled="true" />
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
@using TIAM.Entities.Addresses
|
||||
@using TIAMSharedUI.Shared.Components.Grids
|
||||
@using AyCode.Core
|
||||
@using TIAM.Entities.Products
|
||||
@using TIAM.Entities.Users
|
||||
@layout AdminLayout
|
||||
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
||||
@inject IStringLocalizer<TIAMResources> localizer
|
||||
|
|
@ -125,12 +127,12 @@
|
|||
<CompaniesNestedUserProductMapping CurrentCompany="(TIAM.Entities.ServiceProviders.Company)context.DataItem" KeyboardNavigationEnabled="true" />
|
||||
</DetailRowTemplate> *@
|
||||
<DetailRowTemplate>
|
||||
<DxTabs>
|
||||
<DxTabs ActiveTabIndexChanged="ActiveTabIndexChanged">
|
||||
<DxTabPage Text="Profile">
|
||||
<ProfileGridComponent ProfileId="((Company)context.DataItem).ProfileId" KeyboardNavigationEnabled="true" />
|
||||
<ProfileGridComponent ParentData="((Company)context.DataItem)" KeyboardNavigationEnabled="true" />
|
||||
</DxTabPage>
|
||||
<DxTabPage Text="Products">
|
||||
<ProductDetailGridComponent ProductGrid="" ParentData="(Company)context.DataItem" KeyboardNavigationEnabled="true" />
|
||||
<ProductDetailGridComponent @ref="_productDetailGridComponent" OnGridEditModelSaving="OnProductGridItemSaving" ParentData="(Company)context.DataItem" KeyboardNavigationEnabled="true" />
|
||||
</DxTabPage>
|
||||
<DxTabPage Text="Address">
|
||||
<AddressDetailGridComponent ParentData="((Company)context.DataItem).Profile" KeyboardNavigationEnabled="true" />
|
||||
|
|
@ -163,6 +165,8 @@
|
|||
@code {
|
||||
private LoggerClient<ManageServiceProviders> _logger;
|
||||
|
||||
private ProductDetailGridComponent? _productDetailGridComponent;
|
||||
|
||||
//public Transfer myModel = new Transfer();
|
||||
|
||||
//public List<Company> ServiceProviderDataList { get; set; }
|
||||
|
|
@ -173,7 +177,7 @@
|
|||
private CompanyGrid _gridCompany;
|
||||
private bool _autoCollapseDetailRow;
|
||||
|
||||
private Company CompanyToSetOwner = null;
|
||||
private Company _companyToSetOwner = null;
|
||||
|
||||
public List<string> IgnoreList =
|
||||
[
|
||||
|
|
@ -193,6 +197,7 @@
|
|||
DateTime StartDate { get; set; } = DateTime.Today;
|
||||
DxSchedulerDataStorage _dataStorage = new();
|
||||
|
||||
|
||||
void SendMail(Company item)
|
||||
{
|
||||
_logger.Info($"Sending mail to {item.OwnerId}, {item.Id}");
|
||||
|
|
@ -207,7 +212,7 @@
|
|||
void SetOwnerPopup(Company item)
|
||||
{
|
||||
_logger.Info($"Setting owner of {item.OwnerId}, {item.Id}");
|
||||
CompanyToSetOwner = item;
|
||||
_companyToSetOwner = item;
|
||||
_setOwnerPopupVisible = true;
|
||||
}
|
||||
|
||||
|
|
@ -219,15 +224,15 @@
|
|||
|
||||
//overwrite ServiceProvider ownerid
|
||||
//var target = await serviceProviderDataService.GetServiceProviderByIdAsync(CompanyToSetOwner.Id);
|
||||
if (CompanyToSetOwner == null)
|
||||
if (_companyToSetOwner == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
CompanyToSetOwner.OwnerId = userModelDto.Id;
|
||||
var result = await serviceProviderDataService.UpdateServiceProviderAsync(CompanyToSetOwner);
|
||||
CompanyToSetOwner = null;
|
||||
_companyToSetOwner.OwnerId = userModelDto.Id;
|
||||
var result = await serviceProviderDataService.UpdateServiceProviderAsync(_companyToSetOwner);
|
||||
_companyToSetOwner = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -306,6 +311,30 @@
|
|||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private void OnProductGridItemSaving(GridEditModelSavingEventArgs e)
|
||||
{
|
||||
_logger.Detail($"OnProductGridItemSaving");
|
||||
|
||||
var company = _productDetailGridComponent!.ParentData as Company;
|
||||
if (company == null || company.OwnerId.IsNullOrEmpty())
|
||||
{
|
||||
_logger.Error($"OnProductGridItemSaving; company == null || company.OwnerId.IsNullOrEmpty(); company.OwnerId: {company?.OwnerId}");
|
||||
return;
|
||||
}
|
||||
|
||||
var product = ((Product)e.EditModel);
|
||||
|
||||
if (e.IsNew)
|
||||
{
|
||||
if (product.Id.IsNullOrEmpty()) product.Id = Guid.NewGuid();
|
||||
|
||||
product.ServiceProviderId = company.Id;
|
||||
product.UserProductMappings.Add(new UserProductMapping(company.OwnerId.Value, product.Id) { IsAdmin = true });
|
||||
}
|
||||
else
|
||||
{ }
|
||||
}
|
||||
|
||||
void ColumnChooserButton_Click()
|
||||
{
|
||||
_gridCompany.ShowColumnChooser();
|
||||
|
|
@ -328,4 +357,10 @@
|
|||
_gridCompany.ExpandDetailRow(0);
|
||||
_gridCompany.EndUpdate();
|
||||
}
|
||||
|
||||
private void ActiveTabIndexChanged(int index)
|
||||
{
|
||||
_logger.Detail($"ActiveTabIndexChanged");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
<DetailRowTemplate>
|
||||
<DxTabs>
|
||||
<DxTabPage Text="Profile">
|
||||
<ProfileGridComponent ProfileId="((UserModelDtoDetail)context.DataItem).ProfileDto.Id" KeyboardNavigationEnabled="true" />
|
||||
<ProfileGridComponent ParentData="((UserModelDtoDetail)context.DataItem)" KeyboardNavigationEnabled="true" />
|
||||
</DxTabPage>
|
||||
<DxTabPage Text="Address">
|
||||
<AddressDetailGridComponent ParentData="((UserModelDtoDetail)context.DataItem).ProfileDto" KeyboardNavigationEnabled="true" />
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
@inject AdminSignalRClient AdminSignalRClient;
|
||||
|
||||
|
||||
<ProductDetailGrid @ref="ProductGrid"
|
||||
<ProductDetailGrid @ref="_productGrid"
|
||||
DataSource="ParentData.Products"
|
||||
Logger="_logger"
|
||||
SignalRClient="AdminSignalRClient"
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
<DetailRowTemplate>
|
||||
<DxTabs>
|
||||
<DxTabPage Text="Profile">
|
||||
<ProfileGridComponent ProfileId="((Product)context.DataItem).ProfileId" KeyboardNavigationEnabled="true" />
|
||||
<ProfileGridComponent ParentData="((Product)context.DataItem)" KeyboardNavigationEnabled="true" />
|
||||
</DxTabPage>
|
||||
</DxTabs>
|
||||
</DetailRowTemplate>
|
||||
|
|
@ -82,8 +82,9 @@
|
|||
[Parameter] public bool KeyboardNavigationEnabled { get; set; }
|
||||
[Parameter] public Guid? ContextId { get; set; }
|
||||
[Parameter] public IProductsRelation ParentData { get; set; } = null!;
|
||||
[Parameter] public EventCallback<GridEditModelSavingEventArgs> OnGridEditModelSaving { get; set; }
|
||||
|
||||
public ProductDetailGrid ProductGrid = null!;
|
||||
private ProductDetailGrid _productGrid = null!;
|
||||
private LoggerClient<ProductDetailGridComponent> _logger = null!;
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
|
|
@ -97,31 +98,40 @@
|
|||
{
|
||||
_logger.Debug($"Saving: {args.DataItem.Name}, {args.DataItem.ServiceProviderId}");
|
||||
|
||||
ProductGrid.SaveChangesAsync();
|
||||
//ProductGrid.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void DataItemSaving(GridEditModelSavingEventArgs e)
|
||||
public async Task DataItemSaving(GridEditModelSavingEventArgs e)
|
||||
{
|
||||
await OnGridEditModelSaving.InvokeAsync(e);
|
||||
|
||||
if (e.Cancel) return;
|
||||
|
||||
var product = ((Product)e.EditModel);
|
||||
|
||||
if (e.IsNew)
|
||||
{
|
||||
_logger.Debug($"DataItemSaving");
|
||||
((Product)e.EditModel).ServiceProviderId = (Guid)ContextId!;
|
||||
Guid _profileId = Guid.NewGuid();
|
||||
((Product)e.EditModel).Profile = new Profile();
|
||||
((Product)e.EditModel).Profile.Id = _profileId;
|
||||
((Product)e.EditModel).ProfileId = _profileId;
|
||||
((Product)e.EditModel).Profile.Name = ((Product)e.EditModel).Name;
|
||||
Guid _addressId = Guid.NewGuid();
|
||||
((Product)e.EditModel).Profile.Address = new Address();
|
||||
((Product)e.EditModel).Profile.AddressId = _addressId;
|
||||
((Product)e.EditModel).Profile.Address.Id = _addressId;
|
||||
((Product)e.EditModel).UserProductMappings.Add(new UserProductMapping(Guid.NewGuid, ParentData.));
|
||||
|
||||
var profileId = Guid.NewGuid();
|
||||
product.Profile = new Profile(profileId, product.Name);
|
||||
product.ProfileId = profileId;
|
||||
|
||||
var addressId = Guid.NewGuid();
|
||||
product.Profile.Address = new Address(addressId);
|
||||
product.Profile.AddressId = addressId;
|
||||
|
||||
//((Product)e.EditModel).UserProductMappings.Add(new UserProductMapping(Guid.NewGuid, ParentData.));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_logger.Debug($"Saving: {((Product)e.EditModel).Name}, {((Product)e.EditModel).ServiceProviderId}");
|
||||
}
|
||||
|
||||
_logger.Debug($"Saving: {product.Name}, {product.ServiceProviderId}");
|
||||
|
||||
//var result = serviceProviderDataService.CreateProductAsync((Product)e.EditModel);
|
||||
_logger.Debug($"saved product: {((Product)e.EditModel).ServiceProviderId}");
|
||||
//_logger.Debug($"saved product: {product.ServiceProviderId}");
|
||||
}
|
||||
|
||||
private void DataItemDeleting(GridDataItemDeletingEventArgs obj)
|
||||
|
|
|
|||
|
|
@ -8,13 +8,17 @@
|
|||
@using AyCode.Services.Loggers
|
||||
@using TIAM.Core.Loggers
|
||||
@using AyCode.Core
|
||||
@using AyCode.Interfaces.Profiles.Dtos
|
||||
@using TIAM.Entities.Addresses
|
||||
@using TIAM.Entities.Profiles
|
||||
@using Profile = TIAM.Entities.Profiles.Profile
|
||||
@inject IServiceProviderDataService serviceProviderDataService
|
||||
@inject IUserDataService userDataService
|
||||
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
||||
@inject AdminSignalRClient AdminSignalRClient
|
||||
|
||||
<ProfileDetailGrid @ref="_profileGrid"
|
||||
ContextId="ProfileId"
|
||||
ContextIds="new[] {ParentData.ProfileId}"
|
||||
Logger="_logger"
|
||||
SignalRClient="AdminSignalRClient"
|
||||
PageSize="5"
|
||||
|
|
@ -51,8 +55,8 @@
|
|||
@code {
|
||||
[Parameter]
|
||||
public bool KeyboardNavigationEnabled { get; set; }
|
||||
[Parameter]
|
||||
public Guid ProfileId { get; set; } = Guid.Empty;
|
||||
|
||||
[Parameter] public IProfileForeignKey ParentData { get; set; } = null!;
|
||||
|
||||
private ProfileDetailGrid _profileGrid = null!;
|
||||
private LoggerClient<ProfileGridComponent> _logger = null!;
|
||||
|
|
@ -66,7 +70,7 @@
|
|||
protected override void OnParametersSet()
|
||||
{
|
||||
|
||||
_logger.DebugConditional(ProfileId.ToString());
|
||||
_logger.DebugConditional(ParentData.ProfileId.ToString());
|
||||
base.OnParametersSet();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
case TrackingState.Remove:
|
||||
return await adminDal.RemoveCompanyAsync(company);
|
||||
|
||||
case TrackingState.Get:
|
||||
case TrackingState.GetAll:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(trackingState), trackingState, null);
|
||||
}
|
||||
|
|
@ -262,6 +264,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
case TrackingState.Remove:
|
||||
return await adminDal.RemoveCarAsync(car);
|
||||
|
||||
case TrackingState.Get:
|
||||
case TrackingState.GetAll:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(trackingState), trackingState, null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue