CraftModel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using GreenTree.Strohrmann.ERP.Core.Domain.Business;
  2. using GreenTree.Strohrmann.ERP.Web.Extension;
  3. using GreenTree.Strohrmann.ERP.Web.Models.Search;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Mvc.ViewFeatures;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel.DataAnnotations;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. namespace GreenTree.Strohrmann.ERP.Web.Models.Business
  12. {
  13. public class CraftModel : ICustomerSearchable
  14. {
  15. #region Properties
  16. /// <summary>
  17. /// Craft id
  18. /// </summary>
  19. [Display(Name = "ID")]
  20. public int Id { get; set; }
  21. /// <summary>
  22. /// Craft name
  23. /// </summary>
  24. [Display(Name = "Name")]
  25. public string Name { get; set; }
  26. /// <summary>
  27. /// Craft creation date
  28. /// </summary>
  29. [Display(Name = "Gestartet am")]
  30. [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:dd.MM.yyyy}")]
  31. public DateTime CreationDate { get; set; }
  32. /// <summary>
  33. /// Craft customer
  34. /// </summary>
  35. [Display(Name = "Kunde")]
  36. public CustomerModel Customer { get; set; }
  37. /// <summary>
  38. /// Craft customer id
  39. /// </summary>
  40. [Display(Name = "Kunde")]
  41. public int CustomerId { get; set; }
  42. /// <summary>
  43. /// Craft customer text
  44. /// </summary>
  45. [Display(Name = "Kundenname")]
  46. public string CustomerText { get; set; }
  47. /// <summary>
  48. /// Craft comment
  49. /// </summary>
  50. [Display(Name = "Kommentar")]
  51. public string Comment { get; set; }
  52. /// <summary>
  53. /// Craft employees
  54. /// </summary>
  55. [Display(Name = "Stunden")]
  56. public Dictionary<string, CraftEmployeeModel> CraftEmployees { get; set; }
  57. /// <summary>
  58. /// Craft employee value sum
  59. /// </summary>
  60. [Display(Name = "Wert (Stunden)")]
  61. [DisplayFormat(DataFormatString = "{0:c2}")]
  62. public float CraftEmployeeValue
  63. {
  64. get
  65. {
  66. return CraftEmployees.Sum(ce => ce.Value.Value);
  67. }
  68. }
  69. /// <summary>
  70. /// Craft materials
  71. /// </summary>
  72. [Display(Name = "Material")]
  73. public Dictionary<string, CraftMaterialModel> CraftMaterials { get; set; }
  74. /// <summary>
  75. /// Craft material value sum
  76. /// </summary>
  77. [Display(Name = "Wert (Material)")]
  78. [DisplayFormat(DataFormatString = "{0:c2}")]
  79. public float CraftMaterialValue
  80. {
  81. get
  82. {
  83. return CraftMaterials.Sum(ce => ce.Value.Value);
  84. }
  85. }
  86. #endregion
  87. #region Ctor
  88. /// <summary>
  89. /// Initializes a new instance of the CraftModel class
  90. /// </summary>
  91. public CraftModel() { }
  92. /// <summary>
  93. /// Initializes a new instance of the CraftModel class
  94. /// </summary>
  95. /// <param name="craft">The base craft.</param>
  96. public CraftModel(Craft craft)
  97. {
  98. if (craft == null) return;
  99. Id = craft.Id;
  100. Name = craft.Name;
  101. CreationDate = craft.CreationDate;
  102. Customer = new CustomerModel(craft.Customer);
  103. CustomerText = Customer.Fullname;
  104. CustomerId = craft.Customer.Id;
  105. Comment = craft.Comment;
  106. CraftEmployees = craft.CraftEmployees
  107. .Select(ce => new CraftEmployeeModel(ce))
  108. .ToDictionary(ce => HtmlContentExtension.RandomId(), ce => ce);
  109. CraftMaterials = craft.CraftMaterials
  110. .Select(cm => new CraftMaterialModel(cm))
  111. .ToDictionary(cm => HtmlContentExtension.RandomId(), cm => cm);
  112. }
  113. #endregion
  114. }
  115. }