using GreenTree.Strohrmann.ERP.Core.Domain.Business;
using GreenTree.Strohrmann.ERP.Web.Models.Shared;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace GreenTree.Strohrmann.ERP.Web.Models.Business
{
public class CraftMaterialModel
{
#region Properties
///
/// Craft material model index
///
public int? Index { get; set; }
///
/// Craft material Dictionary identifier
///
public string DictIdentifier { get; set; }
///
/// Craft id
///
[Display(Name = "ID")]
public int CraftId { get; set; }
///
/// Craft
///
[Display(Name = "Gewerk")]
public virtual CraftModel Craft { get; set; }
///
/// Material id
///
[Display(Name = "Material")]
public int MaterialId { get; set; }
///
/// Material
///
[Display(Name = "Material")]
public MaterialModel Material { get; set; }
///
/// Material
///
[Display(Name = "Material")]
public string MaterialText { get; set; }
///
/// The amount of the material
///
[Display(Name = "Menge")]
public float Amount
{
get
{
return String.IsNullOrEmpty(AmountText)
? 0
: Convert.ToSingle(AmountText.Replace('.', ','));
}
set
{
AmountText = value.ToString();
}
}
///
/// The amount of the material as text
///
[Display(Name = "Menge")]
public string AmountText { get; set; }
///
/// The material calculation factor
///
[Display(Name = "Kalkulationsfaktor")]
[DisplayFormat(DataFormatString = "{0:P1}")]
public float CalculationFactor { get; set; }
///
/// The material calculation factor
///
[Display(Name = "Kalkulationsfaktor")]
[DisplayFormat(DataFormatString = "{0:P2}")]
public float CalculationFactorUncalculated
{
get
{
return CalculationFactor / 100;
}
}
///
/// The value of the employee working hours
///
[Display(Name = "Wert")]
[DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:C}")]
public float Value { get; set; }
#endregion
#region Ctor
///
/// Initializes a new instance of the CraftMaterialModel class
///
public CraftMaterialModel() { }
///
/// Initializes a new instance of the CraftMaterialModel class
///
/// The base craft material.
public CraftMaterialModel(CraftMaterial craftMaterial)
{
if (craftMaterial == null) return;
CraftId = craftMaterial.CraftId;
MaterialId = craftMaterial.MaterialId;
Material = new MaterialModel(craftMaterial.Material);
Amount = craftMaterial.Amount;
MaterialText = craftMaterial.Material.Name;
CalculationFactor = craftMaterial.CalculationFactor;
Value = craftMaterial.Value;
}
#endregion
}
}