using System;
using System.Linq;
using Neo.LegitimateLicences.Data.Models;
using Neo.LegitimateLicences.Common;
namespace Neo.LegitimateLicences.Logic.ApplicationLogic
{
public class ApplicationLogic
{
#region VehicleServiceTypeCollectionGet
///
/// Retrieve a collection of comma seperated services types per vehicle
///
///
public VehicleServiceTypeCollection VehicleServiceTypeCollectionGet()
{
var db = new LegitimateDatabase();
VehicleServiceTypeCollection vehicleServiceTypeCollection = new VehicleServiceTypeCollection();
var serviceVehicleTypes = db.GetServiceVehicleTypes();
var busServiceTypeLists = serviceVehicleTypes.Where(a => a.VehicleTypeID == (short)VehicleTypeEnum.Bus).ToList();
var miniBusServiceTypeLists = serviceVehicleTypes.Where(a => a.VehicleTypeID == (short)VehicleTypeEnum.Minibus).ToList();
var midiBusServiceTypeLists = serviceVehicleTypes.Where(a => a.VehicleTypeID == (short)VehicleTypeEnum.Midibus).ToList();
var motorCarServiceTypeLists = serviceVehicleTypes.Where(a => a.VehicleTypeID == (short)VehicleTypeEnum.MotorCar).ToList();
#region Calculate CSV lists
if (busServiceTypeLists != null)
{
vehicleServiceTypeCollection.BusServiceTypes = string.Join(",", busServiceTypeLists.Select(x => x.ServiceTypeID.ToString()).ToArray());
}
else
{
vehicleServiceTypeCollection.BusServiceTypes = "";
}
if (miniBusServiceTypeLists != null)
{
vehicleServiceTypeCollection.MiniBusServiceTypes = string.Join(",", miniBusServiceTypeLists.Select(x => x.ServiceTypeID.ToString()).ToArray());
}
else
{
vehicleServiceTypeCollection.MiniBusServiceTypes = "";
}
if (midiBusServiceTypeLists != null)
{
vehicleServiceTypeCollection.MidiBusServiceTypes = string.Join(",", midiBusServiceTypeLists.Select(x => x.ServiceTypeID.ToString()).ToArray());
}
else
{
vehicleServiceTypeCollection.MidiBusServiceTypes = "";
}
if (motorCarServiceTypeLists != null)
{
vehicleServiceTypeCollection.MotorCarServiceTypes = string.Join(",", motorCarServiceTypeLists.Select(x => x.ServiceTypeID.ToString()).ToArray());
}
else
{
vehicleServiceTypeCollection.MotorCarServiceTypes = "";
}
#endregion
return vehicleServiceTypeCollection;
}
#endregion
}
#region Data Classes
///
/// A collection of comma seperated services types per vehicle
///
public class VehicleServiceTypeCollection
{
public String BusServiceTypes { get; set; }
public String MidiBusServiceTypes { get; set; }
public String MiniBusServiceTypes { get; set; }
public String MotorCarServiceTypes { get; set; }
}
#endregion
}