PersistedGrantMappers.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
  3. using AutoMapper;
  4. using IdentityServer4.Models;
  5. namespace HaBook.IES.IdentityServer.AzureTableStorage.Mappers
  6. {
  7. /// <summary>
  8. /// Extension methods to map to/from entity/model for persisted grants.
  9. /// </summary>
  10. public static class PersistedGrantMappers
  11. {
  12. static PersistedGrantMappers()
  13. {
  14. Mapper = new MapperConfiguration(cfg =>cfg.AddProfile<PersistedGrantMapperProfile>())
  15. .CreateMapper();
  16. }
  17. internal static IMapper Mapper { get; }
  18. /// <summary>
  19. /// Maps an entity to a model.
  20. /// </summary>
  21. /// <param name="entity">The entity.</param>
  22. /// <returns></returns>
  23. public static PersistedGrant ToModel(this Entities.PersistedGrant entity)
  24. {
  25. return entity == null ? null : Mapper.Map<PersistedGrant>(entity);
  26. }
  27. /// <summary>
  28. /// Maps a model to an entity.
  29. /// </summary>
  30. /// <param name="model">The model.</param>
  31. /// <returns></returns>
  32. public static Entities.PersistedGrant ToEntity(this PersistedGrant model)
  33. {
  34. return model == null ? null : Mapper.Map<Entities.PersistedGrant>(model);
  35. }
  36. /// <summary>
  37. /// Updates an entity from a model.
  38. /// </summary>
  39. /// <param name="model">The model.</param>
  40. /// <param name="entity">The entity.</param>
  41. public static void UpdateEntity(this PersistedGrant model, Entities.PersistedGrant entity)
  42. {
  43. Mapper.Map(model, entity);
  44. }
  45. }
  46. }