Skip to content

Commit cbcce39

Browse files
committed
Added statistics. Added migrations.
1 parent 4a79efd commit cbcce39

15 files changed

+389
-4
lines changed

doc/article/article.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ <h2 id="ArticleCreateTemplate">Creating Application From Template</h2>
9090
<h2 id="ArticleEventCloudProject">Event Cloud Project</h2>
9191
<p>In this article, I will show key parts of the project and explain it. So,
9292
please download the sample project, open in Visual Studio 2013+ and run
93-
migrations just like above before reading rest of the article. I will follow
93+
migrations just like above before reading rest of the article (Be sure that
94+
there is no database named EventCloud before running the migrations). I will follow
9495
some <strong>DDD</strong> (Domain Driven Design) techniques to create
9596
<strong>domain (business) layer </strong>and <strong>application layer</strong>.</p>
9697
<p>Event Cloud is a free SaaS (multi-tenant) application. We can create a tenant

src/EventCloud.Application/EventCloud.Application.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
<Compile Include="Properties\AssemblyInfo.cs" />
116116
<Compile Include="Roles\IRoleAppService.cs" />
117117
<Compile Include="Roles\Dto\UpdateRolePermissionsInput.cs" />
118+
<Compile Include="Statistics\IStatisticsAppService.cs" />
119+
<Compile Include="Statistics\StatisticsAppService.cs" />
118120
<Compile Include="Users\IUserAppService.cs" />
119121
<Compile Include="Roles\RoleAppService.cs" />
120122
<Compile Include="Sessions\Dto\GetCurrentLoginInformationsOutput.cs" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Threading.Tasks;
2+
using Abp.Application.Services;
3+
using Abp.Application.Services.Dto;
4+
5+
namespace EventCloud.Statistics
6+
{
7+
public interface IStatisticsAppService : IApplicationService
8+
{
9+
Task<ListResultOutput<NameValueDto>> GetStatistics();
10+
}
11+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using Abp.Application.Services.Dto;
5+
using Abp.Domain.Repositories;
6+
using Abp.Domain.Uow;
7+
using EventCloud.Events;
8+
using EventCloud.MultiTenancy;
9+
using EventCloud.Users;
10+
11+
namespace EventCloud.Statistics
12+
{
13+
public class StatisticsAppService : EventCloudAppServiceBase, IStatisticsAppService
14+
{
15+
private readonly IRepository<Tenant> _tenantRepository;
16+
private readonly IRepository<User, long> _userRepository;
17+
private readonly IRepository<Event, Guid> _eventRepository;
18+
private readonly IRepository<EventRegistration> _eventRegistrationRepository;
19+
20+
public StatisticsAppService(
21+
IRepository<Tenant> tenantRepository,
22+
IRepository<User, long> userRepository,
23+
IRepository<Event, Guid> eventRepository,
24+
IRepository<EventRegistration> eventRegistrationRepository)
25+
{
26+
_tenantRepository = tenantRepository;
27+
_userRepository = userRepository;
28+
_eventRepository = eventRepository;
29+
_eventRegistrationRepository = eventRegistrationRepository;
30+
}
31+
32+
public async Task<ListResultOutput<NameValueDto>> GetStatistics()
33+
{
34+
//Disabled MayHaveTenant filter to access to all tenant's data, not for only current tenant.
35+
using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
36+
{
37+
var statisticItems = new List<NameValueDto>
38+
{
39+
new NameValueDto(
40+
"Tenants",
41+
(await _tenantRepository.CountAsync()).ToString()
42+
),
43+
new NameValueDto(
44+
"Users",
45+
(await _userRepository.CountAsync()).ToString()
46+
),
47+
new NameValueDto(
48+
"Events",
49+
(await _eventRepository.CountAsync()).ToString()
50+
),
51+
new NameValueDto(
52+
"Registrations",
53+
(await _eventRegistrationRepository.CountAsync()).ToString()
54+
)
55+
};
56+
57+
return new ListResultOutput<NameValueDto>(statisticItems);
58+
}
59+
}
60+
}
61+
}

src/EventCloud.EntityFramework/EventCloud.EntityFramework.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
<Compile Include="Migrations\201510210723116_Removed_BirthYear_From_User.Designer.cs">
137137
<DependentUpon>201510210723116_Removed_BirthYear_From_User.cs</DependentUpon>
138138
</Compile>
139+
<Compile Include="Migrations\201510231926262_UpgradeTo_ModuleZero_0_7_3.cs" />
140+
<Compile Include="Migrations\201510231926262_UpgradeTo_ModuleZero_0_7_3.Designer.cs">
141+
<DependentUpon>201510231926262_UpgradeTo_ModuleZero_0_7_3.cs</DependentUpon>
142+
</Compile>
139143
<Compile Include="Migrations\Configuration.cs" />
140144
<Compile Include="EventCloudDataModule.cs" />
141145
<Compile Include="Migrations\SeedData\DefaultTenantRoleAndUserBuilder.cs" />
@@ -174,6 +178,9 @@
174178
<EmbeddedResource Include="Migrations\201510210723116_Removed_BirthYear_From_User.resx">
175179
<DependentUpon>201510210723116_Removed_BirthYear_From_User.cs</DependentUpon>
176180
</EmbeddedResource>
181+
<EmbeddedResource Include="Migrations\201510231926262_UpgradeTo_ModuleZero_0_7_3.resx">
182+
<DependentUpon>201510231926262_UpgradeTo_ModuleZero_0_7_3.cs</DependentUpon>
183+
</EmbeddedResource>
177184
</ItemGroup>
178185
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
179186
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

src/EventCloud.EntityFramework/Migrations/201510231926262_UpgradeTo_ModuleZero_0_7_3.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace EventCloud.Migrations
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data.Entity.Infrastructure.Annotations;
6+
using System.Data.Entity.Migrations;
7+
8+
public partial class UpgradeTo_ModuleZero_0_7_3 : DbMigration
9+
{
10+
public override void Up()
11+
{
12+
CreateTable(
13+
"dbo.AbpFeatures",
14+
c => new
15+
{
16+
Id = c.Long(nullable: false, identity: true),
17+
Name = c.String(nullable: false, maxLength: 128),
18+
Value = c.String(nullable: false, maxLength: 2000),
19+
CreationTime = c.DateTime(nullable: false),
20+
CreatorUserId = c.Long(),
21+
EditionId = c.Int(),
22+
TenantId = c.Int(),
23+
Discriminator = c.String(nullable: false, maxLength: 128),
24+
})
25+
.PrimaryKey(t => t.Id)
26+
.ForeignKey("dbo.AbpEditions", t => t.EditionId)
27+
.Index(t => t.EditionId);
28+
29+
CreateTable(
30+
"dbo.AbpEditions",
31+
c => new
32+
{
33+
Id = c.Int(nullable: false, identity: true),
34+
Name = c.String(nullable: false, maxLength: 32),
35+
DisplayName = c.String(nullable: false, maxLength: 64),
36+
IsDeleted = c.Boolean(nullable: false),
37+
DeleterUserId = c.Long(),
38+
DeletionTime = c.DateTime(),
39+
LastModificationTime = c.DateTime(),
40+
LastModifierUserId = c.Long(),
41+
CreationTime = c.DateTime(nullable: false),
42+
CreatorUserId = c.Long(),
43+
},
44+
annotations: new Dictionary<string, object>
45+
{
46+
{ "DynamicFilter_Edition_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
47+
})
48+
.PrimaryKey(t => t.Id);
49+
50+
AddColumn("dbo.AbpTenants", "EditionId", c => c.Int());
51+
CreateIndex("dbo.AbpTenants", "EditionId");
52+
AddForeignKey("dbo.AbpTenants", "EditionId", "dbo.AbpEditions", "Id");
53+
}
54+
55+
public override void Down()
56+
{
57+
DropForeignKey("dbo.AbpTenants", "EditionId", "dbo.AbpEditions");
58+
DropForeignKey("dbo.AbpFeatures", "EditionId", "dbo.AbpEditions");
59+
DropIndex("dbo.AbpTenants", new[] { "EditionId" });
60+
DropIndex("dbo.AbpFeatures", new[] { "EditionId" });
61+
DropColumn("dbo.AbpTenants", "EditionId");
62+
DropTable("dbo.AbpEditions",
63+
removedAnnotations: new Dictionary<string, object>
64+
{
65+
{ "DynamicFilter_Edition_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
66+
});
67+
DropTable("dbo.AbpFeatures");
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)