140 lines
4.8 KiB
C#
140 lines
4.8 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="CampusBuildingModel.cs" company="BTU/IIT">
|
|
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
|
// </copyright>
|
|
// <author>Stubbfel</author>
|
|
// <date>15.10.2013</date>
|
|
// <summary>Implements the campus building model class</summary>
|
|
//-----------------------------------------------------------------------
|
|
namespace CampusAppWPortalLib8.Model.GeoDb
|
|
{
|
|
using System.Collections.Generic;
|
|
using CampusAppWPortalLib8.Resources;
|
|
|
|
/// <summary> Class is model for buildings of a campus. </summary>
|
|
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
|
/// <typeparam name="T"> Generic type parameter. CampusBuildingLayerModel </typeparam>
|
|
/// <typeparam name="V"> Generic type parameter. PlaceModel </typeparam>
|
|
public class CampusBuildingModel<T, V>
|
|
where V : PlaceModel
|
|
where T : CampusBuildingLayerModel<V>, new()
|
|
{
|
|
#region constructor
|
|
|
|
/// <summary> Initializes a new instance of the CampusBuildingModel class. </summary>
|
|
/// <remarks> Stubbfel, 21.10.2013. </remarks>
|
|
public CampusBuildingModel()
|
|
{
|
|
}
|
|
|
|
/// <summary> Initializes a new instance of the CampusBuildingModel class. </summary>
|
|
/// <remarks> Stubbfel, 21.10.2013. </remarks>
|
|
/// <param name="buildingId"> The identifier of the building. </param>
|
|
/// <param name="places"> list of place which can be room of the buildings. </param>
|
|
public CampusBuildingModel(string buildingId, List<V> places)
|
|
{
|
|
this.BuildingId = buildingId;
|
|
|
|
this.AddLayers(places);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary> Gets the Layer of the building. </summary>
|
|
/// <value> The layers. </value>
|
|
public Dictionary<string, T> Layers { get; private set; }
|
|
|
|
/// <summary> Gets or sets the Building V. </summary>
|
|
/// <value> The building. </value>
|
|
public V Building { get; set; }
|
|
|
|
/// <summary> Gets or sets the identifier of the building. </summary>
|
|
/// <value> The identifier of the building. </value>
|
|
public string BuildingId { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region method
|
|
|
|
/// <summary> Adds the layers. </summary>
|
|
/// <remarks> Stubbfel, 21.10.2013. </remarks>
|
|
/// <param name="places"> list of place which can be room of the buildings. </param>
|
|
public void AddLayers(List<V> places)
|
|
{
|
|
if (this.Layers == null)
|
|
{
|
|
this.Layers = new Dictionary<string, T>();
|
|
}
|
|
|
|
foreach (V place in places)
|
|
{
|
|
if (place.ParentId.Equals(this.BuildingId))
|
|
{
|
|
string placeLayerId = place.GetInformationsValue(Constants.PisInformationName_Layer);
|
|
if (placeLayerId == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (this.Layers.ContainsKey(placeLayerId))
|
|
{
|
|
this.Layers[placeLayerId].Rooms.Places.Add(place);
|
|
}
|
|
else
|
|
{
|
|
T layer = new T() { LayerId = placeLayerId };
|
|
layer.AddsRooms(new List<V> { place });
|
|
this.Layers.Add(placeLayerId, layer);
|
|
}
|
|
}
|
|
else if (place.PlaceId.Equals(this.BuildingId))
|
|
{
|
|
this.Building = place;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary> Method gets a place by their placeID. </summary>
|
|
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
|
/// <param name="placeID"> the placeId of the place. </param>
|
|
/// <returns> The place by identifier. </returns>
|
|
public V GetPlaceById(string placeID)
|
|
{
|
|
V result = null;
|
|
foreach (T layer in this.Layers.Values)
|
|
{
|
|
result = layer.Rooms.GetPlaceById(placeID);
|
|
if (result != null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary> Gets layer key. </summary>
|
|
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
|
/// <param name="placeId"> Identifier for the place. </param>
|
|
/// <returns> The layer key. </returns>
|
|
public string GetLayerKey(string placeId)
|
|
{
|
|
V tmpPlace = null;
|
|
foreach (T layer in this.Layers.Values)
|
|
{
|
|
tmpPlace = layer.Rooms.GetPlaceById(placeId);
|
|
if (tmpPlace != null)
|
|
{
|
|
return layer.LayerId;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|