CraftModel.cs 4.5 KB

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