This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected IEnumerable<ViewModels.Shared.Localization> CreateLocalizationsFor(LocalizationSet localizationSet) | |
{ | |
ICultureRepository cultureRepository = this.HttpContext.RequestServices.GetService<ICultureRepository>(); | |
return cultureRepository.GetAll() | |
.Select(c => new ViewModels.Shared.Localization() { CultureCode = c.Code, Value = localizationSet.Localizations.FirstOrDefault(l => l.CultureCode == c.Code)?.Value }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Book GetById(int id) | |
{ | |
return this.storage.Books | |
.Include(b => b.Name).ThenInclude(ls => ls.Localizations) | |
.Include(b => b.Description).ThenInclude(ls => ls.Localizations) | |
.Include(b => b.Author).ThenInclude(ls => ls.Localizations) | |
.FirstOrDefault(b => b.Id == id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected IEnumerable<ViewModels.Shared.Localization> CreateEmptyLocalizations() | |
{ | |
ICultureRepository cultureRepository = this.HttpContext.RequestServices.GetService<ICultureRepository>(); | |
return cultureRepository.GetAll().Select(c => new ViewModels.Shared.Localization() { CultureCode = c.Code }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
[ImportModelStateFromTempData] | |
public IActionResult AddOrEdit(int? id) | |
{ | |
AddOrEdit addOrEdit = new AddOrEdit(); | |
if (id == null) | |
{ | |
addOrEdit.NameLocalizations = this.CreateEmptyLocalizations(); | |
addOrEdit.DescriptionLocalizations = this.CreateEmptyLocalizations(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Localization : ViewModelBase | |
{ | |
public string CultureCode { get; set; } | |
public string Value { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocalizableAttribute : Attribute | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddOrEdit : ViewModelBase | |
{ | |
public int? Id { get; set; } | |
[Localizable] | |
[Display(Name = "Name")] | |
[Required] | |
[StringLength(64)] | |
public string Name { get; set; } | |
public IEnumerable<Localization> NameLocalizations { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="content__table table" cellpadding="0" cellspacing="0"> | |
<tr class="table__row"> | |
<th class="table__cell table__cell--heading">@Localizer["ID"]</th> | |
<th class="table__cell table__cell--heading">@Localizer["Name"]</th> | |
<th class="table__cell table__cell--heading">@Localizer["Description"]</th> | |
<th class="table__cell table__cell--heading">@Localizer["Author"]</th> | |
<th class="table__cell table__cell--heading">@Localizer["Year"]</th> | |
<th class="table__cell table__cell--heading"> </th> | |
</tr> | |
@foreach (var book in this.Model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IActionResult Index() | |
{ | |
return this.View( | |
localizedBookRepository.GetAll(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName) | |
.Select(b => new Book() { Id = b.Id, Name = b.Name, Description = b.Description, Author = b.Author, Year = b.Year }) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT "b"."Id", "lName"."Value" AS "Name", "lDescription"."Value" AS "Description", "lAuthor"."Value" AS "Author", "b"."Year" | |
FROM "Books" AS "b" | |
INNER JOIN "Localizations" AS "lName" ON "b"."NameId" = "lName"."LocalizationSetId" | |
INNER JOIN "Localizations" AS "lDescription" ON "b"."DescriptionId" = "lDescription"."LocalizationSetId" | |
INNER JOIN "Localizations" AS "lAuthor" ON "b"."AuthorId" = "lAuthor"."LocalizationSetId" | |
WHERE (("lName"."CultureCode" = 'en') AND ("lDescription"."CultureCode" = 'en')) AND ("lAuthor"."CultureCode" = 'en') |