tbf/Results/Entities/Components.cs

95 lines
2.9 KiB
C#

///
/// 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;
}
/// <summary>
/// Method to compare the content of two entities
/// </summary>
/// <param name="wmd">Second entity to compare with</param>
/// <returns>first = two entities are equal (except of Id)</returns>
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;
}
/// <summary>
/// Adds an item to the list if it does not occur there
/// </summary>
/// <param name="list">List of items</param>
/// <param name="item">Item to add to the list or find there</param>
/// <returns>Item from the list (existing or added)</returns>
public static Components UpdateList(IList<Components> list, Components item)
{
if (item == null) return null; /// Null item is not stored in the list
Components found = list.FirstOrDefault<Components>(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;
}
}
}