| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace GreenTree.Nachtragsmanagement.Web.Models.Appendix
- {
- public class AppendixDataModel : IRequireStateDataModel
- {
- public int Id { get; set; }
- public string CustomNumber { get; set; }
- public string Description { get; set; }
- public decimal? Probability { get; set; }
- public int? OfferingNumber { get; set; }
- public DateTime? OfferingDate { get; set; }
- public decimal OfferingValue { get; set; }
- public decimal Percentage { get; set; }
- public decimal PercentageValue { get; set; }
- public DateTime? NegotiationDate { get; set; }
- public decimal? NegotiationValue { get; set; }
- public bool ProtocolExists { get; set; }
- public int? OrderNumber { get; set; }
- public DateTime? OrderDate { get; set; }
- public bool OrderInvoiceCreated { get; set; }
- public string Comment { get; set; }
- public int? StateId { get; set; }
- public string StateDescription { get; set; }
- public int? SiteId { get; set; }
- public string SiteDescription { get; set; }
- public ICollection<int> DeviationValues { get; set; }
- public ICollection<string> DeviationDescriptions { get; set; }
- public string DeviationDescription { get; set; }
- public ICollection<string> CategoryEntities { get; set; }
- public ICollection<CategoryValueDataModel> CategoryValueEntities { get; set; }
- public string CategoryValuesDescription
- {
- get
- {
- if (CategoryValueEntities == null)
- return String.Empty;
- else
- return String.Join(", ", CategoryValueEntities.Select(d => d.Description));
- }
- }
- public AppendixDataModel()
- {
- DeviationValues = new List<int>();
- DeviationDescriptions = new List<string>();
- CategoryEntities = new List<string>();
- CategoryValueEntities = new List<CategoryValueDataModel>();
- }
- public static AppendixDataModel FromAppendix(Core.Domain.Appendix.Appendix appendixEntity, bool newWhenIsNull)
- {
- if (appendixEntity == null && newWhenIsNull)
- return new AppendixDataModel
- {
- Id = -1,
- Percentage = 50
- };
- if (appendixEntity == null && !newWhenIsNull)
- throw new ArgumentNullException("appendixEntity", "Cannot create AppendixDataModel from NULL appendix entity.");
- var model = new AppendixDataModel
- {
- Id = appendixEntity.Id,
- CustomNumber = appendixEntity.CustomNumber,
- Description = appendixEntity.Description,
- Percentage = appendixEntity.Percentage.HasValue
- ? appendixEntity.Percentage.Value
- : (decimal)0.5,
- PercentageValue = appendixEntity.Value.HasValue && appendixEntity.Percentage.HasValue
- ? appendixEntity.Value.Value * appendixEntity.Percentage.Value
- : 0,
- OfferingNumber = appendixEntity.OfferingNumber,
- OfferingDate = appendixEntity.OfferingDate,
- OfferingValue = appendixEntity.Value.Value,
- NegotiationDate = appendixEntity.NegotiationDate,
- NegotiationValue = appendixEntity.NegotiationValue,
- ProtocolExists = appendixEntity.ProtocolExists,
- OrderNumber = appendixEntity.OrderNumber,
- OrderDate = appendixEntity.OrderDate,
- Comment = appendixEntity.Comment,
- OrderInvoiceCreated = appendixEntity.OrderInvoiceCreated,
- StateId = appendixEntity.StateId,
- StateDescription = appendixEntity.State == null
- ? null
- : appendixEntity.State.Description,
- SiteId = appendixEntity.SiteId,
- SiteDescription = appendixEntity.Site == null
- ? null
- : appendixEntity.Site.Description,
- CategoryValueEntities =
- appendixEntity.CategoryValues
- .Select(r =>
- new CategoryValueDataModel
- {
- CategoryId = r.CategoryId,
- Description = String.Format("{0} - {1:c2}", r.Category.Description, r.Value),
- Value = r.Value
- })
- .ToList(),
- DeviationValues =
- appendixEntity.Deviations
- .Select(r => r.Id)
- .ToList(),
- DeviationDescriptions =
- appendixEntity.Deviations
- .Select(r => r.CustomNumber)
- .ToList(),
- DeviationDescription =
- String.Join(", ",
- appendixEntity.Deviations
- .Select(d => d.CustomNumber))
- };
- foreach (var disturbance in model.CategoryValueEntities)
- {
- var json = JsonConvert.SerializeObject(disturbance);
- disturbance.Json = json;
- model.CategoryEntities.Add(json);
- }
- return model;
- }
- public Core.Domain.Appendix.Appendix ToAppendix()
- {
- return new Core.Domain.Appendix.Appendix
- {
- Id = this.Id,
- CustomNumber = this.CustomNumber,
- Description = this.Description,
- Percentage = this.Percentage,
- StateId = this.StateId,
- Value = this.OfferingValue,
- OfferingNumber = this.OfferingNumber,
- OfferingDate = this.OfferingDate,
- NegotiationDate = this.NegotiationDate,
- NegotiationValue = this.NegotiationValue,
- ProtocolExists = this.ProtocolExists,
- OrderNumber = this.OrderNumber,
- OrderDate = this.OrderDate,
- Comment = this.Comment,
- SiteId = this.SiteId
- };
- }
- }
- }
|