CraftModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using GreenTree.Strohrmann.ERP.Core.Domain.Business;
  2. using GreenTree.Strohrmann.ERP.Web.Extension;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.ViewFeatures;
  5. using Microsoft.EntityFrameworkCore.Internal;
  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
  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. /// <summary>
  87. /// Craft value sum
  88. /// </summary>
  89. [Display(Name = "Wert (Gesamt)")]
  90. [DisplayFormat(DataFormatString = "{0:c2}")]
  91. public float CraftValue
  92. {
  93. get
  94. {
  95. return CraftEmployeeValue + CraftMaterialValue;
  96. }
  97. }
  98. #endregion
  99. #region Ctor
  100. /// <summary>
  101. /// Initializes a new instance of the CraftModel class
  102. /// </summary>
  103. public CraftModel() { }
  104. /// <summary>
  105. /// Initializes a new instance of the CraftModel class
  106. /// </summary>
  107. /// <param name="craft">The base craft.</param>
  108. public CraftModel(Craft craft)
  109. {
  110. if (craft == null) return;
  111. Id = craft.Id;
  112. Name = craft.Name;
  113. CreationDate = craft.CreationDate;
  114. Customer = new CustomerModel(craft.Customer);
  115. CustomerText = Customer.Fullname;
  116. CustomerId = craft.Customer.Id;
  117. Comment = craft.Comment;
  118. CraftEmployees = craft.CraftEmployees
  119. .Select(ce => new CraftEmployeeModel(ce))
  120. .ToDictionary(ce => HtmlContentExtension.RandomId(), ce => ce);
  121. CraftMaterials = craft.CraftMaterials
  122. .Select(cm => new CraftMaterialModel(cm))
  123. .ToDictionary(cm => HtmlContentExtension.RandomId(), cm => cm);
  124. var index = 0;
  125. foreach (var item in CraftEmployees)
  126. {
  127. item.Value.Index = index;
  128. index++;
  129. }
  130. index = 0;
  131. foreach (var item in CraftMaterials)
  132. {
  133. item.Value.Index = index;
  134. index++;
  135. }
  136. }
  137. #endregion
  138. }
  139. }