StateConfigurationReference.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Autofac;
  2. using GreenTree.Nachtragsmanagement.Core;
  3. using GreenTree.Nachtragsmanagement.Services.Appendix;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace GreenTree.Nachtragsmanagement.Services.Configuration
  10. {
  11. public class StateConfigurationReference : IConfigurationReference
  12. {
  13. /// <summary>
  14. /// Id
  15. /// </summary>
  16. public Guid Id
  17. {
  18. get
  19. {
  20. return Guid.Parse("DF5E3C83-357C-458D-AA03-9BF7C5C49203");
  21. }
  22. }
  23. /// <summary>
  24. /// Internal name
  25. /// </summary>
  26. public string Name
  27. {
  28. get
  29. {
  30. return "ConfigurationReference.StateConfigurationReference";
  31. }
  32. }
  33. /// <summary>
  34. /// Display name
  35. /// </summary>
  36. public string DisplayName
  37. {
  38. get
  39. {
  40. return "Nachtragsstatus";
  41. }
  42. }
  43. /// <summary>
  44. /// Determines if mutiple values are selectable
  45. /// </summary>
  46. public bool IsMultipleSelection
  47. {
  48. get
  49. {
  50. return true;
  51. }
  52. }
  53. /// <summary>
  54. /// Get available values
  55. /// </summary>
  56. public ConfigurationReferenceElement[] GetAvailableValues()
  57. {
  58. var appendixService = Singleton<IContainer>.Instance.Resolve<IAppendixService>();
  59. return
  60. appendixService
  61. .GetAllStates()
  62. .Select(s => new ConfigurationReferenceElement
  63. {
  64. Value = s.Id,
  65. Text = s.Description
  66. })
  67. .ToArray();
  68. }
  69. /// <summary>
  70. /// Transforms mutiple selected values into a single line value
  71. /// </summary>
  72. /// <param name="values">Selected values.</param>
  73. public string TransformValueCollectionToValue(string[] values)
  74. {
  75. return
  76. String.Join(", ", values);
  77. }
  78. /// <summary>
  79. /// Transforms the single line value into a mutiple selected values
  80. /// </summary>
  81. /// <param name="value">Single line value.</param>
  82. public string[] TransformValueToValueCollection(string value)
  83. {
  84. return
  85. String.IsNullOrEmpty(value)
  86. ? new string[0]
  87. : value.Split(',')
  88. .Select(s => s.Trim())
  89. .ToArray();
  90. }
  91. /// <summary>
  92. /// Converts the string converted value into strongly typed value
  93. /// </summary>
  94. /// <param name="values">The selected value.</param>
  95. public T GetValue<T>(string value)
  96. {
  97. return (T)((object)Convert.ToInt32(value));
  98. }
  99. /// <summary>
  100. /// Converts the string converted values into strongly typed values
  101. /// </summary>
  102. /// <param name="values">The selected values.</param>
  103. public T GetValues<T>(string[] values)
  104. {
  105. if (values == null)
  106. return default(T);
  107. return
  108. (T)(
  109. (object)
  110. (values
  111. .Select(v => Convert.ToInt32(v))
  112. .ToArray()));
  113. }
  114. }
  115. }