| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace GreenTree.Nachtragsmanagement.Web.Models.Deviation
- {
- public class DeviationDataModel
- : IRequireAppendixDataModel, IRequireStatusDataModel, IRequireDisturbanceDataModel, IRequireKindDataModel
- {
- public int Id { get; set; }
- public string CustomNumber { get; set; }
- public string Description { get; set; }
- public DateTime? ReceiptDate { get; set; }
- public DateTime? AppendixDate { get; set; }
- public decimal Value { get; set; }
- public int Percentage { get; set; }
- public decimal PercentageValue { get; set; }
- public int? StatusId { get; set; }
- public string StatusDescription { get; set; }
- public int? KindId { get; set; }
- public string KindDescription { get; set; }
- public string Comment { get; set; }
- public string SiteDescription { get; set; }
- public int? SiteId { get; set; }
- public string AppendixDescription { get; set; }
- public int? AppendixId { get; set; }
- public ICollection<int> DisturbanceValues { get; set; }
- public ICollection<string> DisturbanceDescriptions { get; set; }
- public string DisturbanceDescription
- {
- get
- {
- if (DisturbanceDescriptions == null)
- return String.Empty;
- else
- return String.Join(", ", DisturbanceDescriptions);
- }
- }
- public DeviationDataModel()
- {
- DisturbanceValues = new List<int>();
- DisturbanceDescriptions = new List<string>();
- }
- public static DeviationDataModel FromDeviation(Core.Domain.Deviation.Deviation deviationEntity, bool newWhenIsNull)
- {
- if (deviationEntity == null && newWhenIsNull)
- return new DeviationDataModel
- {
- Id = -1,
- Percentage = 100
- };
- if (deviationEntity == null && !newWhenIsNull)
- throw new ArgumentNullException("deviationEntity", "Cannot create DeviationDataModel from NULL deviation entity.");
- return new DeviationDataModel
- {
- Id = deviationEntity.Id,
- CustomNumber = deviationEntity.CustomNumber,
- Description = deviationEntity.Description,
- ReceiptDate = deviationEntity.ReceiptDate,
- AppendixDate = deviationEntity.AppendixDate,
- Value = deviationEntity.Value.Value,
- Percentage = deviationEntity.Percentage.Value,
- PercentageValue = deviationEntity.Value.Value * (deviationEntity.Percentage.Value / 100),
- SiteId = deviationEntity.SiteId,
- SiteDescription = deviationEntity.Site == null
- ? null
- : deviationEntity.Site.CustomNumber,
- AppendixId = deviationEntity.AppendixId,
- AppendixDescription = deviationEntity.Appendix == null
- ? null
- : deviationEntity.Appendix.CustomNumber,
- StatusId = deviationEntity.StatusId.Value,
- StatusDescription = deviationEntity.Status == null
- ? null
- : deviationEntity.Status.Description,
- KindId = deviationEntity.KindId.Value,
- KindDescription = deviationEntity.Kind == null
- ? null
- : deviationEntity.Kind.Description,
- Comment = deviationEntity.Comment,
- DisturbanceValues =
- deviationEntity.DisturbanceValues
- .Select(r => r.Id)
- .ToList(),
- DisturbanceDescriptions =
- deviationEntity.DisturbanceValues
- .Select(r => r.Disturbance == null
- ? String.Empty
- : r.Disturbance.Description)
- .ToList()
- };
- }
- public Core.Domain.Deviation.Deviation ToDeviation()
- {
- return new Core.Domain.Deviation.Deviation
- {
- Id = this.Id,
- CustomNumber = this.CustomNumber,
- Description = Description,
- ReceiptDate = this.ReceiptDate,
- AppendixDate = this.AppendixDate,
- Value = this.Value,
- Percentage = this.Percentage,
- SiteId = this.SiteId,
- AppendixId = this.AppendixId,
- StatusId = this.StatusId,
- KindId = this.KindId,
- Comment = this.Comment
- };
- }
- }
- }
|