Skip to content

Commit

Permalink
Added statistics. Added migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed Oct 23, 2015
1 parent 4a79efd commit cbcce39
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 4 deletions.
3 changes: 2 additions & 1 deletion doc/article/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ <h2 id="ArticleCreateTemplate">Creating Application From Template</h2>
<h2 id="ArticleEventCloudProject">Event Cloud Project</h2>
<p>In this article, I will show key parts of the project and explain it. So,
please download the sample project, open in Visual Studio 2013+ and run
migrations just like above before reading rest of the article. I will follow
migrations just like above before reading rest of the article (Be sure that
there is no database named EventCloud before running the migrations). I will follow
some <strong>DDD</strong> (Domain Driven Design) techniques to create
<strong>domain (business) layer </strong>and <strong>application layer</strong>.</p>
<p>Event Cloud is a free SaaS (multi-tenant) application. We can create a tenant
Expand Down
2 changes: 2 additions & 0 deletions src/EventCloud.Application/EventCloud.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Roles\IRoleAppService.cs" />
<Compile Include="Roles\Dto\UpdateRolePermissionsInput.cs" />
<Compile Include="Statistics\IStatisticsAppService.cs" />
<Compile Include="Statistics\StatisticsAppService.cs" />
<Compile Include="Users\IUserAppService.cs" />
<Compile Include="Roles\RoleAppService.cs" />
<Compile Include="Sessions\Dto\GetCurrentLoginInformationsOutput.cs" />
Expand Down
11 changes: 11 additions & 0 deletions src/EventCloud.Application/Statistics/IStatisticsAppService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Abp.Application.Services;
using Abp.Application.Services.Dto;

namespace EventCloud.Statistics
{
public interface IStatisticsAppService : IApplicationService
{
Task<ListResultOutput<NameValueDto>> GetStatistics();
}
}
61 changes: 61 additions & 0 deletions src/EventCloud.Application/Statistics/StatisticsAppService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using EventCloud.Events;
using EventCloud.MultiTenancy;
using EventCloud.Users;

namespace EventCloud.Statistics
{
public class StatisticsAppService : EventCloudAppServiceBase, IStatisticsAppService
{
private readonly IRepository<Tenant> _tenantRepository;
private readonly IRepository<User, long> _userRepository;
private readonly IRepository<Event, Guid> _eventRepository;
private readonly IRepository<EventRegistration> _eventRegistrationRepository;

public StatisticsAppService(
IRepository<Tenant> tenantRepository,
IRepository<User, long> userRepository,
IRepository<Event, Guid> eventRepository,
IRepository<EventRegistration> eventRegistrationRepository)
{
_tenantRepository = tenantRepository;
_userRepository = userRepository;
_eventRepository = eventRepository;
_eventRegistrationRepository = eventRegistrationRepository;
}

public async Task<ListResultOutput<NameValueDto>> GetStatistics()
{
//Disabled MayHaveTenant filter to access to all tenant's data, not for only current tenant.
using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
{
var statisticItems = new List<NameValueDto>
{
new NameValueDto(
"Tenants",
(await _tenantRepository.CountAsync()).ToString()
),
new NameValueDto(
"Users",
(await _userRepository.CountAsync()).ToString()
),
new NameValueDto(
"Events",
(await _eventRepository.CountAsync()).ToString()
),
new NameValueDto(
"Registrations",
(await _eventRegistrationRepository.CountAsync()).ToString()
)
};

return new ListResultOutput<NameValueDto>(statisticItems);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
<Compile Include="Migrations\201510210723116_Removed_BirthYear_From_User.Designer.cs">
<DependentUpon>201510210723116_Removed_BirthYear_From_User.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201510231926262_UpgradeTo_ModuleZero_0_7_3.cs" />
<Compile Include="Migrations\201510231926262_UpgradeTo_ModuleZero_0_7_3.Designer.cs">
<DependentUpon>201510231926262_UpgradeTo_ModuleZero_0_7_3.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="EventCloudDataModule.cs" />
<Compile Include="Migrations\SeedData\DefaultTenantRoleAndUserBuilder.cs" />
Expand Down Expand Up @@ -174,6 +178,9 @@
<EmbeddedResource Include="Migrations\201510210723116_Removed_BirthYear_From_User.resx">
<DependentUpon>201510210723116_Removed_BirthYear_From_User.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201510231926262_UpgradeTo_ModuleZero_0_7_3.resx">
<DependentUpon>201510231926262_UpgradeTo_ModuleZero_0_7_3.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace EventCloud.Migrations
{
using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.Migrations;

public partial class UpgradeTo_ModuleZero_0_7_3 : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.AbpFeatures",
c => new
{
Id = c.Long(nullable: false, identity: true),
Name = c.String(nullable: false, maxLength: 128),
Value = c.String(nullable: false, maxLength: 2000),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Long(),
EditionId = c.Int(),
TenantId = c.Int(),
Discriminator = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AbpEditions", t => t.EditionId)
.Index(t => t.EditionId);

CreateTable(
"dbo.AbpEditions",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(nullable: false, maxLength: 32),
DisplayName = c.String(nullable: false, maxLength: 64),
IsDeleted = c.Boolean(nullable: false),
DeleterUserId = c.Long(),
DeletionTime = c.DateTime(),
LastModificationTime = c.DateTime(),
LastModifierUserId = c.Long(),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Long(),
},
annotations: new Dictionary<string, object>
{
{ "DynamicFilter_Edition_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);

AddColumn("dbo.AbpTenants", "EditionId", c => c.Int());
CreateIndex("dbo.AbpTenants", "EditionId");
AddForeignKey("dbo.AbpTenants", "EditionId", "dbo.AbpEditions", "Id");
}

public override void Down()
{
DropForeignKey("dbo.AbpTenants", "EditionId", "dbo.AbpEditions");
DropForeignKey("dbo.AbpFeatures", "EditionId", "dbo.AbpEditions");
DropIndex("dbo.AbpTenants", new[] { "EditionId" });
DropIndex("dbo.AbpFeatures", new[] { "EditionId" });
DropColumn("dbo.AbpTenants", "EditionId");
DropTable("dbo.AbpEditions",
removedAnnotations: new Dictionary<string, object>
{
{ "DynamicFilter_Edition_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
});
DropTable("dbo.AbpFeatures");
}
}
}
Loading

0 comments on commit cbcce39

Please sign in to comment.