| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace GreenTree.Nachtragsmanagement.Web.Models.Site
- {
- public class SiteTreeDataModel
- {
- public int Id { get; set; }
- public string TreeKey { get; set; }
- public string TreeParentKey { get; set; }
- public string CustomNumber { get; set; }
- public string Description { get; set; }
- public DateTime? ReceiptDate { get; set; }
- public decimal? Value { get; set; }
- public int? StatusId { get; set; }
- public string StatusDescription { get; set; }
- public string StatusColor { get; set; }
- public ICollection<int> DistCatValues { get; set; }
- public ICollection<string> DistCatDescriptions { get; set; }
- public string DistCatDescription
- {
- get
- {
- if (DistCatDescriptions == null)
- return String.Empty;
- else
- return String.Join(", ", DistCatDescriptions);
- }
- }
- public string Comment { get; set; }
- public SiteTreeDataModel()
- {
- DistCatValues = new List<int>();
- DistCatDescriptions = new List<string>();
- }
- public static List<SiteTreeDataModel> TreeFromSite(Core.Domain.Site.Site siteEntity)
- {
- var result = new List<SiteTreeDataModel>();
- if (siteEntity == null)
- return result;
- var openDeviations = siteEntity.Deviations
- .Where(d => d.Appendix == null);
- var emptyAppendix = new SiteTreeDataModel
- {
- Id = 0,
- TreeKey = "a_0",
- TreeParentKey = String.Empty,
- CustomNumber = "Offene VA",
- Description = openDeviations.Count() > 0
- ? String.Format("{0} offene VAs", openDeviations.Count())
- : "Keine offenen VAs"
- };
- result.Add(emptyAppendix);
- foreach (var openDeviation in openDeviations)
- {
- result.Add(new SiteTreeDataModel
- {
- Id = openDeviation.Id,
- TreeKey = String.Format("d_{0}", openDeviation.Id),
- TreeParentKey = emptyAppendix.TreeKey,
- CustomNumber = openDeviation.CustomNumber,
- Description = openDeviation.Description,
- ReceiptDate = openDeviation.ReceiptDate,
- DistCatValues =
- openDeviation.DisturbanceValues
- .Select(d => d.Id)
- .ToList(),
- DistCatDescriptions =
- openDeviation.DisturbanceValues
- .Select(r => r.Disturbance == null
- ? String.Empty
- : r.Disturbance.Description)
- .ToList(),
- StatusId = openDeviation.StatusId,
- StatusDescription = openDeviation.Status == null
- ? String.Empty
- : openDeviation.Status.Description,
- Value = openDeviation.Value.Value * openDeviation.Percentage.Value,
- Comment = openDeviation.Comment
- });
- }
- foreach (var appendix in siteEntity.Appendices)
- {
- var parentAppendix = new SiteTreeDataModel
- {
- Id = appendix.Id,
- TreeKey = String.Format("a_{0}", appendix.Id),
- TreeParentKey = String.Empty,
- CustomNumber = appendix.CustomNumber,
- Description = appendix.Description,
- ReceiptDate = appendix.OfferingDate,
- DistCatValues =
- appendix.CategoryValues
- .Select(d => d.Id)
- .ToList(),
- DistCatDescriptions =
- appendix.CategoryValues
- .Select(r => r.Category == null
- ? String.Empty
- : r.Category.Description)
- .ToList(),
- StatusId = appendix.StateId,
- StatusDescription = appendix.State == null
- ? String.Empty
- : appendix.State.Description,
- StatusColor = appendix.State == null
- ? "#FFFFFF"
- : appendix.State.HexColor,
- Value = appendix.NegotiationValue,
- Comment = appendix.Comment
- };
- result.Add(parentAppendix);
- foreach (var deviation in appendix.Deviations)
- {
- var childDeviation = new SiteTreeDataModel
- {
- Id = deviation.Id,
- TreeKey = String.Format("d_{0}", deviation.Id),
- TreeParentKey = parentAppendix.TreeKey,
- CustomNumber = deviation.CustomNumber,
- Description = deviation.Description,
- ReceiptDate = deviation.ReceiptDate,
- DistCatValues =
- deviation.DisturbanceValues
- .Select(d => d.Id)
- .ToList(),
- DistCatDescriptions =
- deviation.DisturbanceValues
- .Select(r => r.Disturbance == null
- ? String.Empty
- : r.Disturbance.Description)
- .ToList(),
- StatusId = deviation.StatusId,
- StatusDescription = deviation.Status == null
- ? String.Empty
- : deviation.Status.Description,
- Value = deviation.Value.Value * deviation.Percentage.Value,
- Comment = deviation.Comment
- };
- result.Add(childDeviation);
- }
- }
- return result;
- }
- }
- }
|