/// /// Copyright (c) 2016 Sensus Metering Systems /// using System; using System.Collections.Generic; using System.Linq; namespace Results.Entities { public class Components { public virtual int Id { get; protected set; } public virtual int TestBenchId { get; set; } public virtual string TestBenchName { get; set; } public virtual string Pump { get; set; } public virtual string RegValve { get; set; } public virtual string Flowmeter { get; set; } public virtual string Diverter { get; set; } public virtual string Scale { get; set; } public virtual string Custom1 { get; set; } public virtual string Custom2 { get; set; } public virtual string Custom3 { get; set; } protected Components() { TestBenchId = 0; TestBenchName = string.Empty; Pump = string.Empty; RegValve = string.Empty; Flowmeter = string.Empty; Diverter = string.Empty; Scale = string.Empty; Custom1 = string.Empty; Custom2 = string.Empty; Custom3 = string.Empty; } public Components(int benchId, string benchName, string pump, string flowmeter, string scale, string regValve, string diverter) { TestBenchId = benchId; TestBenchName = benchName; Pump = pump; RegValve = regValve; Flowmeter = flowmeter; Diverter = diverter; Scale = scale; Custom1 = string.Empty; Custom2 = string.Empty; Custom3 = string.Empty; } /// /// Method to compare the content of two entities /// /// Second entity to compare with /// first = two entities are equal (except of Id) public virtual bool Equals(Components bc) { if (TestBenchId != bc.TestBenchId) return false; if (!TestBenchName.Equals(bc.TestBenchName)) return false; if (!Pump.Equals(bc.Pump)) return false; if (!RegValve.Equals(bc.RegValve)) return false; if (!Flowmeter.Equals(bc.Flowmeter)) return false; if (!Diverter.Equals(bc.Diverter)) return false; if (!Scale.Equals(bc.Scale)) return false; if (!Custom1.Equals(bc.Custom1)) return false; if (!Custom2.Equals(bc.Custom2)) return false; if (!Custom3.Equals(bc.Custom3)) return false; return true; } /// /// Adds an item to the list if it does not occur there /// /// List of items /// Item to add to the list or find there /// Item from the list (existing or added) public static Components UpdateList(IList list, Components item) { if (item == null) return null; /// Null item is not stored in the list Components found = list.FirstOrDefault(x => x.Equals(item)); if (found != null) return found; /// The same item found in the list, The found item returned list.Add(item); /// Item not fund in the list, it is added to the list return item; } } }