Skip to content

Commit

Permalink
add language and update LanguageResource
Browse files Browse the repository at this point in the history
  • Loading branch information
emrecoskun705 committed Sep 19, 2023
1 parent 2102ab1 commit 53ba7d5
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 16 deletions.
12 changes: 12 additions & 0 deletions Unitagram.Domain/Language.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Unitagram.Domain.Common;

namespace Unitagram.Domain;

public class Language : BaseEntity
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Culture { get; set; } = string.Empty;

public ICollection<LanguageResource>? LanguageResources { get; set; }
}
7 changes: 4 additions & 3 deletions Unitagram.Domain/LanguageResource.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using Unitagram.Domain;
using Unitagram.Domain.Common;
using Unitagram.Domain.Primitives;

namespace Unitagram.Domain;

public class LanguageResource : BaseEntity, IAuditableEntity
{
public int Id { get; set; }
public string Language { get; set; } = string.Empty;
public int LanguageId { get; set; }
public string Source { get; set; } = string.Empty;
public string SourceKey { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
public string? ModifiedBy { get; set; }
public string? CreatedBy { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime? ModifiedOnUtc { get; set; }

public Language Language { get; set; }
}
5 changes: 2 additions & 3 deletions Unitagram.Infrastructure/Unitagram.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
</ItemGroup>


<ItemGroup>
<Folder Include="LocalizationCache\" />
</ItemGroup>



</Project>
19 changes: 19 additions & 0 deletions Unitagram.Persistence/Configurations/LanguageConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Unitagram.Domain;

namespace Unitagram.Persistence.Configurations;

public class LanguageConfiguration : IEntityTypeConfiguration<Language>
{
public void Configure(EntityTypeBuilder<Language> builder)
{
builder.HasKey(u => u.Id);

builder.Property(u => u.Culture)
.HasMaxLength(5);

builder.Property(u => u.Name)
.HasMaxLength(30);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ public class LanguageResourceConfiguration : IEntityTypeConfiguration<LanguageRe
{
public void Configure(EntityTypeBuilder<LanguageResource> builder)
{
builder.HasKey(u => new {u.Id, u.Language, u.Source, u.SourceKey});

builder.Property(u => u.Language)
.HasMaxLength(5);
builder.HasKey(u => new {u.Id, u.Source, u.SourceKey});

builder.Property(u => u.Source)
.HasMaxLength(20);
Expand All @@ -24,5 +21,10 @@ public void Configure(EntityTypeBuilder<LanguageResource> builder)

builder.Property(u => u.CreatedBy)
.HasMaxLength(15);

builder
.HasOne(lr => lr.Language)
.WithMany(l => l.LanguageResources)
.HasForeignKey(lr => lr.LanguageId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected UnitagramDatabaseContext()
public DbSet<UniversityUser> UniversityUser { get; set; }
public DbSet<OtpConfirmation> OtpConfirmation { get; set; }
public DbSet<LanguageResource> LanguageResource { get; set; }
public DbSet<Language> Language { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
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,97 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Unitagram.Persistence.Migrations
{
/// <inheritdoc />
public partial class UpdateLanguageResource : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_LanguageResource",
table: "LanguageResource");

migrationBuilder.DropColumn(
name: "Language",
table: "LanguageResource");

migrationBuilder.AddColumn<int>(
name: "LanguageId",
table: "LanguageResource",
type: "int",
nullable: false,
defaultValue: 0);

migrationBuilder.AddPrimaryKey(
name: "PK_LanguageResource",
table: "LanguageResource",
columns: new[] { "Id", "Source", "SourceKey" });

migrationBuilder.CreateTable(
name: "Language",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(30)", maxLength: 30, nullable: false),
Culture = table.Column<string>(type: "nvarchar(5)", maxLength: 5, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Language", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "IX_LanguageResource_LanguageId",
table: "LanguageResource",
column: "LanguageId");

migrationBuilder.AddForeignKey(
name: "FK_LanguageResource_Language_LanguageId",
table: "LanguageResource",
column: "LanguageId",
principalTable: "Language",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_LanguageResource_Language_LanguageId",
table: "LanguageResource");

migrationBuilder.DropTable(
name: "Language");

migrationBuilder.DropPrimaryKey(
name: "PK_LanguageResource",
table: "LanguageResource");

migrationBuilder.DropIndex(
name: "IX_LanguageResource_LanguageId",
table: "LanguageResource");

migrationBuilder.DropColumn(
name: "LanguageId",
table: "LanguageResource");

migrationBuilder.AddColumn<string>(
name: "Language",
table: "LanguageResource",
type: "nvarchar(5)",
maxLength: 5,
nullable: false,
defaultValue: "");

migrationBuilder.AddPrimaryKey(
name: "PK_LanguageResource",
table: "LanguageResource",
columns: new[] { "Id", "Language", "Source", "SourceKey" });
}
}
}
Loading

0 comments on commit 53ba7d5

Please sign in to comment.