Files
win8phoneApp/CampusAppWP8/CampusAppWPortalLib8/Model/GeoDb/CampusBuildingModel.cs
2013-10-22 14:01:48 +02:00

135 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>
public class CampusBuildingModel
{
#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<PlaceModel> 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, CampusBuildingLayerModel> Layers { get; private set; }
/// <summary> Gets or sets the Building PlaceModel. </summary>
/// <value> The building. </value>
public PlaceModel 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<PlaceModel> places)
{
if (this.Layers == null)
{
this.Layers = new Dictionary<string, CampusBuildingLayerModel>();
}
foreach (PlaceModel 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
{
CampusBuildingLayerModel layer = new CampusBuildingLayerModel() { LayerId = placeLayerId };
layer.AddsRooms(new List<PlaceModel> { 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 PlaceModel GetPlaceById(string placeID)
{
PlaceModel result = null;
foreach (CampusBuildingLayerModel 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)
{
PlaceModel tmpPlace = null;
foreach (CampusBuildingLayerModel layer in this.Layers.Values)
{
tmpPlace = layer.Rooms.GetPlaceById(placeId);
if (tmpPlace != null)
{
return layer.LayerId;
}
}
return null;
}
#endregion
}
}