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 Person | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public DateTime Birthday { get; set; } | |
public int AddressId { get; set; } | |
public virtual Address Address { get; set; } | |
} | |
public class Address |
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 interface IDto<TModel> where TModel : class, new() | |
{ | |
} |
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 PersonFormDto: IDto<Person> | |
{ | |
public int Id { get; set; } | |
[Required(ErrorMessage = "Hey why don't you tell me who you are?!")] | |
public string Name { get; set; } | |
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] | |
[Required(ErrorMessage = "Come on now, don't be shy.")] | |
public DateTime Birthday { 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
/// <summary> | |
/// Custom injection to support nested DTO properties | |
/// </summary> | |
public class DtoInjection: LoopValueInjection | |
{ | |
/// <summary> | |
/// If one of the types implements IDto, check if its generic type parameter | |
/// matches the other type | |
/// Otherwise, just use the default typematcher. | |
/// </summary> |
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 static class DtoExtensions | |
{ | |
/// <summary> | |
/// Make a new model and inject dto values | |
/// </summary> | |
/// <typeparam name="TModel">The type of the model</typeparam> | |
/// <param name="dto">The dto object that contains the property values</param> | |
/// <returns>A new instance of TModel with the same property values of this dto</returns> | |
public static TModel ToModel<TModel>(this IDto<TModel> dto) | |
where TModel : class, new() |
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 PeopleController: Controller | |
{ | |
private IRepository<Person> _people; | |
public PeopleController(IRepository<Person> people) | |
{ | |
_people = people; | |
} | |
public ActionResult Index() |
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 Product | |
{ | |
public int Id { get; set; } | |
public MultilingualString Name { get; set; } | |
public MultilingualString Description { 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
var product1 = new Product(); | |
product1.Name["en"] = "Product 1"; | |
product1.Description["fr"] = "Description 1"; | |
product1.Name["fr"] = "Produit 1"; | |
product1.Description["fr"] = "Déscription 1"; | |
product1.Name["nl"] = "Produkt 1"; | |
product1.Description["nl"] = "Omschrijving 1"; |
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
/// <summary> | |
/// Represents a string that can be translated into several languages. | |
/// </summary> | |
public class MultilingualString | |
{ | |
private const string TranslationsNode = "translations"; | |
private const string TranslationNode = "translation"; | |
private const string LanguageNode = "language"; | |
private const string ValueNode = "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
<translations> | |
<translation> | |
<language>en</language> | |
<value>Description 1</value> | |
</translation> | |
<translation> | |
<language>fr</language> | |
<value>Déscription 1</value> |
OlderNewer