using GreenTree.Strohrmann.ERP.Core.Domain.Business;
using GreenTree.Strohrmann.ERP.Web.Extension;
using GreenTree.Strohrmann.ERP.Web.Models.Search;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
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 CraftModel : ICustomerSearchable
{
#region Properties
///
/// Craft id
///
[Display(Name = "ID")]
public int Id { get; set; }
///
/// Craft name
///
[Display(Name = "Name")]
public string Name { get; set; }
///
/// Craft creation date
///
[Display(Name = "Gestartet am")]
[DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:dd.MM.yyyy}")]
public DateTime CreationDate { get; set; }
///
/// Craft customer
///
[Display(Name = "Kunde")]
public CustomerModel Customer { get; set; }
///
/// Craft customer id
///
[Display(Name = "Kunde")]
public int CustomerId { get; set; }
///
/// Craft customer text
///
[Display(Name = "Kundenname")]
public string CustomerText { get; set; }
///
/// Craft comment
///
[Display(Name = "Kommentar")]
public string Comment { get; set; }
///
/// Craft employees
///
[Display(Name = "Stunden")]
public Dictionary CraftEmployees { get; set; }
///
/// Craft employee value sum
///
[Display(Name = "Wert (Stunden)")]
[DisplayFormat(DataFormatString = "{0:c2}")]
public float CraftEmployeeValue
{
get
{
return CraftEmployees.Sum(ce => ce.Value.Value);
}
}
///
/// Craft materials
///
[Display(Name = "Material")]
public Dictionary CraftMaterials { get; set; }
///
/// Craft material value sum
///
[Display(Name = "Wert (Material)")]
[DisplayFormat(DataFormatString = "{0:c2}")]
public float CraftMaterialValue
{
get
{
return CraftMaterials.Sum(ce => ce.Value.Value);
}
}
#endregion
#region Ctor
///
/// Initializes a new instance of the CraftModel class
///
public CraftModel() { }
///
/// Initializes a new instance of the CraftModel class
///
/// The base craft.
public CraftModel(Craft craft)
{
if (craft == null) return;
Id = craft.Id;
Name = craft.Name;
CreationDate = craft.CreationDate;
Customer = new CustomerModel(craft.Customer);
CustomerText = Customer.Fullname;
CustomerId = craft.Customer.Id;
Comment = craft.Comment;
CraftEmployees = craft.CraftEmployees
.Select(ce => new CraftEmployeeModel(ce))
.ToDictionary(ce => HtmlContentExtension.RandomId(), ce => ce);
CraftMaterials = craft.CraftMaterials
.Select(cm => new CraftMaterialModel(cm))
.ToDictionary(cm => HtmlContentExtension.RandomId(), cm => cm);
}
#endregion
}
}