diff --git a/src/SplashPage.Application/Splash/ISplashDashboardService.cs b/src/SplashPage.Application/Splash/ISplashDashboardService.cs index 39b17dbb..c21835fc 100644 --- a/src/SplashPage.Application/Splash/ISplashDashboardService.cs +++ b/src/SplashPage.Application/Splash/ISplashDashboardService.cs @@ -12,6 +12,7 @@ namespace SplashPage.Splash Task SaveDashboard(int dashboardId, List widgets); Task> GetDashboards(); Task CreateDashboard(CreateSplashDashboardDto model); + Task UpdateDashboard(UpdateSplashDashboardDto model); Task DuplicateDashboard(DuplicateSplashDashboardDto model); [HttpDelete] diff --git a/src/SplashPage.Application/Splash/SplashDashboardService.cs b/src/SplashPage.Application/Splash/SplashDashboardService.cs index e92502d3..eb6ef6b5 100644 --- a/src/SplashPage.Application/Splash/SplashDashboardService.cs +++ b/src/SplashPage.Application/Splash/SplashDashboardService.cs @@ -14,6 +14,7 @@ using System.Threading.Tasks; using static System.Runtime.InteropServices.JavaScript.JSType; using Abp.Authorization; using SplashPage.Authorization; +using Abp.EntityFrameworkCore.Repositories; namespace SplashPage.Splash { @@ -25,6 +26,7 @@ namespace SplashPage.Splash private readonly IRepository _splashAccessPointRepository; private readonly IRepository _networkGroupRepository; private readonly IRepository _networkGroupMemberRepository; + private readonly IRepository _widgetRepository; private readonly SplashNetworkGroupManager _networkGroupManager; private readonly IUnitOfWorkManager _unitOfWorkManager; public SplashDashboardService(IRepository splashDashboardRepository, @@ -33,7 +35,8 @@ namespace SplashPage.Splash IRepository splashAccessPointRepository, IRepository networkGroupRepository, IRepository networkGroupMemberRepository, - SplashNetworkGroupManager networkGroupManager) + SplashNetworkGroupManager networkGroupManager + , IRepository widgetRepository) { _splashDashboardRepository = splashDashboardRepository; _unitOfWorkManager = unitOfWorkManager; @@ -42,6 +45,7 @@ namespace SplashPage.Splash _networkGroupRepository = networkGroupRepository; _networkGroupMemberRepository = networkGroupMemberRepository; _networkGroupManager = networkGroupManager; + _widgetRepository = widgetRepository; } //[AbpAuthorize(PermissionNames.Pages_Dashboards_Create)] @@ -833,7 +837,9 @@ namespace SplashPage.Splash throw new Abp.UI.UserFriendlyException($"Dashboard with ID {dashboardId} not found"); } + await _widgetRepository.BatchDeleteAsync(x => x.DashboardId == dashboardId); await _splashDashboardRepository.DeleteAsync(dashboard); + CurrentUnitOfWork.SaveChanges(); Logger.Info($"DeleteDashboard: Successfully deleted dashboard with ID {dashboardId}"); } diff --git a/src/SplashPage.Core/Splash/SplashDashboard.cs b/src/SplashPage.Core/Splash/SplashDashboard.cs index fb0e85fb..8d68eb23 100644 --- a/src/SplashPage.Core/Splash/SplashDashboard.cs +++ b/src/SplashPage.Core/Splash/SplashDashboard.cs @@ -22,6 +22,7 @@ namespace SplashPage.Splash SelectedNetworks = selectedNetworks; StartDate = DateTime.UtcNow; EndDate = DateTime.UtcNow.AddDays(-1); + Widgets= new List(); } diff --git a/src/SplashPage.Core/Splash/SplashWidget.cs b/src/SplashPage.Core/Splash/SplashWidget.cs index e5b5d717..80488d7f 100644 --- a/src/SplashPage.Core/Splash/SplashWidget.cs +++ b/src/SplashPage.Core/Splash/SplashWidget.cs @@ -19,6 +19,9 @@ namespace SplashPage.Splash public int WidgetType { get; set; } public string Content { get; set; } + public int DashboardId { get; set; } + public SplashDashboard Dashboard { get; set; } + //Implementations public DateTime CreationTime { get; set; } public int TenantId { get; set; } diff --git a/src/SplashPage.EntityFrameworkCore/Configurations/SplashWidgetConfiguration.cs b/src/SplashPage.EntityFrameworkCore/Configurations/SplashWidgetConfiguration.cs new file mode 100644 index 00000000..dc052d89 --- /dev/null +++ b/src/SplashPage.EntityFrameworkCore/Configurations/SplashWidgetConfiguration.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using SplashPage.Splash; + +namespace SplashPage.Configurations +{ + public class SplashWidgetConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("SplashWidgets"); + + builder.Property(x => x.Id) + .ValueGeneratedOnAdd(); + + builder.Property(x => x.DashboardId) + .HasColumnName("SplashDashboardId"); + + builder.HasOne(x => x.Dashboard) + .WithMany(x => x.Widgets) + .HasForeignKey(x => x.DashboardId); + } + } +}