CraftModel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 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 : ICustomerSearchable
  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. #endregion
  88. #region Ctor
  89. /// <summary>
  90. /// Initializes a new instance of the CraftModel class
  91. /// </summary>
  92. public CraftModel() { }
  93. /// <summary>
  94. /// Initializes a new instance of the CraftModel class
  95. /// </summary>
  96. /// <param name="craft">The base craft.</param>
  97. public CraftModel(Craft craft)
  98. {
  99. if (craft == null) return;
  100. Id = craft.Id;
  101. Name = craft.Name;
  102. CreationDate = craft.CreationDate;
  103. Customer = new CustomerModel(craft.Customer);
  104. CustomerText = Customer.Fullname;
  105. CustomerId = craft.Customer.Id;
  106. Comment = craft.Comment;
  107. CraftEmployees = craft.CraftEmployees
  108. .Select(ce => new CraftEmployeeModel(ce))
  109. .ToDictionary(ce => HtmlContentExtension.RandomId(), ce => ce);
  110. CraftMaterials = craft.CraftMaterials
  111. .Select(cm => new CraftMaterialModel(cm))
  112. .ToDictionary(cm => HtmlContentExtension.RandomId(), cm => cm);
  113. var index = 0;
  114. foreach (var item in CraftEmployees)
  115. {
  116. item.Value.Index = index;
  117. index++;
  118. }
  119. index = 0;
  120. foreach (var item in CraftMaterials)
  121. {
  122. item.Value.Index = index;
  123. index++;
  124. }
  125. }
  126. #endregion
  127. }
  128. }