ExampleAppinator

Hey all…today I’ll be posting the code for generating my ExampleAppinator project.  It’s the project I’ll be using for all my posts going forward and is something I’ll just continue to grow as I learn new things.  I had been using my Super Duper All Encompassing Wonder App that I’ve been developing for work…but it’s getting to hard to strip out all the PI and NDA stuff before posting to the blog so I decided to just create a special project just for the blog and ExampleAppinator was born.  I’ll be updating this thread whenever I make a change to anything so if anyone actually wants to try the things I’m doing it should be all you need to plug into VS to make things works (assuming you have all the same SDK’s and whatnot I’m using, hehehe).

 

KitchenSink Database:

This database is just a mashing together of any example tables I’ve used in previous posts.  I did my best to fit the tables together in a relational way without having a plan in place ahead of time…it should be usable for future examples though.

Engine Table:

CREATE TABLE [dbo].[Engine]
(
    [Id]            INT IDENTITY(1, 1) NOT NULL,
    [Make]          NVARCHAR(50) NOT NULL,
    [Cylenders]     INT NOT NULL,
    [Displacement]  NVARCHAR(20) NOT NULL,
    [Horsepower]    INT NOT NULL, 

    CONSTRAINT PK_Engine PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT UNIQUE_Engine UNIQUE ([Make], [Cylenders], [Displacement])
)
GO

CREATE NONCLUSTERED INDEX NCI_Make
ON [Engine]([Make] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Cylenders
ON [Engine]([Cylenders] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Displacement
ON [Engine]([Displacement] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Horsepower
ON [Engine]([Horsepower] ASC)

History Table:

CREATE TABLE [dbo].[History]
(
    [Id]            INT IDENTITY(1, 1) NOT NULL,
    [Source]        NVARCHAR(100) NOT NULL,
    [Message]       NVARCHAR(MAX) NOT NULL,
    [LastUpdate]    DATETIME2(7) NOT NULL, 

    CONSTRAINT PK_History PRIMARY KEY CLUSTERED ([Id] ASC)
)
GO

CREATE NONCLUSTERED INDEX NCI_Source
ON [History]([Source] ASC);
GO

CREATE NONCLUSTERED INDEX NCI_LastUpdate
ON [History](LastUpdate ASC);

Lifeform Table:

CREATE TABLE [dbo].[Lifeform]
(
    [Id]            INT IDENTITY(1, 1) NOT NULL,
    [SpeciesId]     INT NOT NULL,
    [PlanetId]      INT NOT NULL,
    [VehicleId]     INT,
    [Name]          NVARCHAR(100) NOT NULL,
    [Age]           INT NOT NULL, 

    CONSTRAINT PK_Lifeform PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT UNIQUE_Lifeform UNIQUE ([SpeciesId], [PlanetId], [Name]),
    CONSTRAINT FK_Lifeform_SpeciesId FOREIGN KEY ([SpeciesId]) REFERENCES [Species]([Id]),
    CONSTRAINT FK_Lifeform_PlanetId FOREIGN KEY ([PlanetId]) REFERENCES [Planet]([Id]),
    CONSTRAINT FK_Lifeform_VehicleId FOREIGN KEY ([VehicleId]) REFERENCES [Vehicle]([Id])
)
GO

CREATE NONCLUSTERED INDEX NCI_SpeciesId
ON [Lifeform]([SpeciesId] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_PlanetId
ON [Lifeform]([PlanetId] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_VehicleId
ON [Lifeform]([VehicleId] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Name
ON [Lifeform]([Name] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Age
ON [Lifeform]([Age] ASC)

Planet Table:

CREATE TABLE [dbo].[Planet]
(
    [Id]    INT IDENTITY(1, 1) NOT NULL,
    [Name]  NVARCHAR(100) NOT NULL, 

    CONSTRAINT PK_Planet PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT UNIQUE_Planet UNIQUE ([Name])
)
GO

CREATE NONCLUSTERED INDEX NCI_Name
ON [Planet]([Name] ASC)

Species Table:

CREATE TABLE [dbo].[Species]
(
    [Id]            INT IDENTITY(1, 1) NOT NULL,
    [Name]          NVARCHAR(100) NOT NULL

    CONSTRAINT PK_Species PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT UNIQUE_Species UNIQUE ([Name])
)
GO

CREATE NONCLUSTERED INDEX NCI_Name
ON [Species]([Name] ASC)

Vehicle Table:

CREATE TABLE [dbo].[Vehicle]
(
    [Id]                    INT IDENTITY(1, 1) NOT NULL,
    [EngineId]              INT NOT NULL,
    [Make]                  NVARCHAR(50) NOT NULL,
    [Model]                 NVARCHAR(100) NOT NULL,
    [Year]                  INT NOT NULL,
    [WheelCount]            INT NOT NULL,
    [PassengerCapacity]     INT NOT NULL, 

    CONSTRAINT PK_Vehicle PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT UNIQUE_Vehicle UNIQUE ([EngineId], [Make], [Model], [Year]),
    CONSTRAINT FK_Vehicle_EngineId FOREIGN KEY ([EngineId]) REFERENCES [Engine]([Id])
)
GO

CREATE NONCLUSTERED INDEX NCI_EngineId
ON [Vehicle]([EngineId] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Make
ON [Vehicle]([Make] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Model
ON [Vehicle]([Model] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_Year
ON [Vehicle]([Year] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_WheelCount
ON [Vehicle]([WheelCount] ASC)
GO

CREATE NONCLUSTERED INDEX NCI_PassengerCapacity
ON [Vehicle]([PassengerCapacity] ASC)

 

KitchenSinkDLL:

This is a library that other .net projects can reference to get access to the database.  Sure you could go setup EF or Linq to SQL classes to do that…which is what is happening under the covers of KitchenSinkDLL, but this also provides a Model layer which can be easily be used in WPF or MVC apps.  I’ll be posting the code for the C# classes and a snapshot of my Linq To SQL design surface.  I will not be posted the autogen’d code made by Linq To SQL because no one needs to see that mess.  🙂

EngineModel Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace KitchenSinkDLL.Models
{
    public class EngineModel
    {
        public EngineModel()
        {
            Initialize(0, string.Empty, 0, string.Empty, 0);
        }

        public EngineModel(string make, int cylenders, string displacement, int horsepower)
        {
            Initialize(0, make, cylenders, displacement, horsepower);
        }

        public EngineModel(int id)
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            Engine engine = dataContext.Engines
                .SingleOrDefault(e => e.Id == id);

            if (engine != null)
            {
                Initialize(engine.Id, engine.Make, engine.Cylenders, engine.Displacement, engine.Horsepower);
            }
            else
            {
                Initialize(0, string.Empty, 0, string.Empty, 0);
            }
        }

        public EngineModel(Engine engine)
        {
            if(engine != null)
            {
                Initialize(engine.Id, engine.Make, engine.Cylenders, engine.Displacement, engine.Horsepower);
            }
            else
            {
                Initialize(0, string.Empty, 0, string.Empty, 0);
            }
        }

        private void Initialize(int id, string make, int cylenders, string displacement, int horsepower)
        {
            Id = id;
            Make = make;
            Cylenders = cylenders;
            Displacement = displacement;
            Horsepower = horsepower;
        }

        public int Id { get; set; }

        public string Make { get; set; }

        public int Cylenders { get; set; }

        public string Displacement { get; set; }

        public int Horsepower { get; set; }

        public EngineModel CreateEngine()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id > 0 ||
                string.IsNullOrEmpty(Make) ||
                Cylenders <= 0 ||
                string.IsNullOrEmpty(Displacement) ||
                Horsepower <= 0)
            {
                Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");
                return null;
            }

            Engine addTarget = new Engine();
            addTarget.Make = Make;
            addTarget.Cylenders = Cylenders;
            addTarget.Displacement = Displacement;
            addTarget.Horsepower = Horsepower;
            dataContext.Engines.InsertOnSubmit(addTarget);

            try
            {
                dataContext.SubmitChanges();
                Id = addTarget.Id;
                HistoryModel.CreateHistoryRecord(callingMethod, $"Created [Engine] with Id: {Id}");
            }
            catch (Exception exception)
            {
                Logger.LogException(callingMethod, exception);
                HistoryModel.CreateHistoryRecord(callingMethod, $"Create [Engine] failed.  Error: {exception.Message}");
                return null;
            }

            return this;
        }

        public EngineModel DeleteEngine()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0)             {                 Logger.LogError(callingMethod, "The Id must be greater than 0.");                 return null;             }             Engine deleteTarget = dataContext.Engines                 .SingleOrDefault(e => e.Id == Id);

            if (deleteTarget != null)
            {
                dataContext.Engines.DeleteOnSubmit(deleteTarget);

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Deleted [Engine] with Id: {Id}");
                    Id = 0;
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Delete [Engine] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public EngineModel UpdateEngine()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0 ||
                string.IsNullOrEmpty(Make) ||
                Cylenders <= 0 ||
                string.IsNullOrEmpty(Displacement) ||
                Horsepower <= 0)             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             Engine updateTarget = dataContext.Engines                 .SingleOrDefault(e => e.Id == Id);

            if (updateTarget != null)
            {
                updateTarget.Make = Make;
                updateTarget.Cylenders = Cylenders;
                updateTarget.Displacement = Displacement;
                updateTarget.Horsepower = Horsepower;

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Updated [Engine] with Id: {Id}");
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
 HistoryModel.CreateHistoryRecord(callingMethod, $"Update [Engine] failed. Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public static IEnumerable<EngineModel> ReadEngines()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Engines.ToEngineModelCollection().OrderBy(e => e.Id);
        }
    }
}

namespace KitchenSinkDLL
{
    public static partial class Extensions
    {
        public static IEnumerable<EngineModel> ToEngineModelCollection(this IQueryable<Engine> engines)
        {
            List<EngineModel> returnCollection = new List<EngineModel>();

            if (engines != null)
            {
                foreach (var engine in engines)
                {
                    EngineModel newModel = new EngineModel(engine);
                    returnCollection.Add(newModel);
                }
            }

            return returnCollection;
        }
    }
}

HistoryModel Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace KitchenSinkDLL.Models
{
    public class HistoryModel
    {
        public HistoryModel()
        {
            Initialize(0, string.Empty, string.Empty, DateTime.MinValue);
        }

        public HistoryModel(string source, string message)
        {
            Initialize(0, source, message, DateTime.MinValue);
        }

        public HistoryModel(int id)
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            History historyRecord = dataContext.Histories
                .SingleOrDefault(h => h.Id == id);

            if (historyRecord != null)
            {
                Initialize(historyRecord.Id, historyRecord.Source, historyRecord.Message, historyRecord.LastUpdate);
            }
            else
            {
                Initialize(0, string.Empty, string.Empty, DateTime.MinValue);
            }

        }

        public HistoryModel(History historyRecord)
        {
            if (historyRecord != null)
            {
                Initialize(historyRecord.Id, historyRecord.Source, historyRecord.Message, historyRecord.LastUpdate);
            }
            else
            {
                Initialize(0, string.Empty, string.Empty, DateTime.MinValue);
            }
        }

        private void Initialize(int id, string source, string message, DateTime lastUpdate)
        {
            Id = id;
            Source = source;
            Message = message;
            LastUpdate = lastUpdate;
        }

        public int Id { get; set; }

        public string Source { get; set; }

        public string Message { get; set; }

        public DateTime LastUpdate { get; set; }

        public HistoryModel CreateHistory()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id > 0 ||
                string.IsNullOrEmpty(Source) ||
                string.IsNullOrEmpty(Message))
            {
                Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");
                return null;
            }

            History addTarget = new History();
            addTarget.Source = Source;
            addTarget.Message = Message;
            addTarget.LastUpdate = DateTime.Now;
            dataContext.Histories.InsertOnSubmit(addTarget);

            try
            {
                dataContext.SubmitChanges();
                Id = addTarget.Id;
                LastUpdate = addTarget.LastUpdate;
            }
            catch (Exception exception)
            {
                Logger.LogException(callingMethod, exception);
                return null;
            }

            return this;
        }

        public HistoryModel DeleteHistory()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0)             {                 Logger.LogError(callingMethod, "The Id must be greater than 0.");                 return null;             }             History deleteTarget = dataContext.Histories                 .SingleOrDefault(h => h.Id == Id);

            if (deleteTarget != null)
            {
                dataContext.Histories.DeleteOnSubmit(deleteTarget);

                try
                {
                    dataContext.SubmitChanges();
                    Id = 0;
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public HistoryModel UpdateHistory()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0 ||                 string.IsNullOrEmpty(Source) ||                 string.IsNullOrEmpty(Message))             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             History updateTarget = dataContext.Histories                 .SingleOrDefault(h => h.Id == Id);

            if (updateTarget != null)
            {
                updateTarget.Source = Source;
                updateTarget.Message = Message;
                updateTarget.LastUpdate = LastUpdate;

                try
                {
                    dataContext.SubmitChanges();
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        internal static HistoryModel CreateHistoryRecord(string source, string message)
        {
            HistoryModel historyEntry = new HistoryModel(source, message);
            return historyEntry.CreateHistory();
        }

        public static IEnumerable<HistoryModel> ReadHistoryRecords()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Histories.ToHistoryModelCollection().OrderBy(h => h.Id);
        }

        public static DateTime ReadLastHistoryUpdate()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Histories.Max(h => h.LastUpdate);
        }
    }
}

namespace KitchenSinkDLL
{
    public static partial class Extensions
    {
        public static IEnumerable<HistoryModel> ToHistoryModelCollection(this IQueryable<History> historyRecords)
        {
            List<HistoryModel> returnCollection = new List<HistoryModel>();

            if (historyRecords != null)
            {
                foreach (var historyRecord in historyRecords)
                {
                    HistoryModel newModel = new HistoryModel(historyRecord);
                    returnCollection.Add(newModel);
                }
            }

            return returnCollection;
        }
    }
}

KitchenSinkDLL Class:

using System.Data;

namespace KitchenSinkDLL
{
    public class KitchenSinkDLL
    {
        internal static KitchenSinkLinqToSqlDataContext CreateDataContext(string callingMethod)
        {
            KitchenSinkLinqToSqlDataContext dataContext = new KitchenSinkLinqToSqlDataContext();

            if (!dataContext.DatabaseExists() && dataContext.Connection.State != ConnectionState.Open)
            {
                Logger.LogError(callingMethod, "Unable to write to the database.");
                return null;
            }

            return dataContext;
        }
    }
}

LifeformModel Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace KitchenSinkDLL.Models
{
    public class LifeformModel
    {
        public LifeformModel()
        {
            Initialize(0, new SpeciesModel(), new PlanetModel(), new VehicleModel(), string.Empty, 0);
        }

        public LifeformModel(int speciesId, int planetId, int vehicleId, string name, int age)
        {
            Initialize(0, new SpeciesModel(speciesId), new PlanetModel(planetId), new VehicleModel(vehicleId), name, age);
        }

        public LifeformModel(SpeciesModel speciesModel, PlanetModel planetModel, VehicleModel vehicleModel, string name, int age)
        {
            Initialize(0, speciesModel, planetModel, vehicleModel, name, age);
        }

        public LifeformModel(int id, SpeciesModel speciesModel, PlanetModel planetModel, VehicleModel vehicleModel, string name, int age)
        {
            Initialize(id, speciesModel, planetModel, vehicleModel, name, age);
        }
        public LifeformModel(int id)
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            Lifeform lifeform = dataContext.Lifeforms
                .SingleOrDefault(l => l.Id == id);

            if (lifeform != null)
            {
                Initialize(lifeform.Id, new SpeciesModel(lifeform.Specy), new PlanetModel(lifeform.Planet), new VehicleModel(lifeform.Vehicle), lifeform.Name, lifeform.Age);
            }
            else
            {
                Initialize(0, new SpeciesModel(), new PlanetModel(), new VehicleModel(), string.Empty, 0);
            }
        }

        public LifeformModel(Lifeform lifeform)
        {
            if (lifeform != null)
            {
                Initialize(lifeform.Id, new SpeciesModel(lifeform.Specy), new PlanetModel(lifeform.Planet), new VehicleModel(lifeform.Vehicle), lifeform.Name, lifeform.Age);
            }
            else
            {
                Initialize(0, new SpeciesModel(), new PlanetModel(), new VehicleModel(), string.Empty, 0);
            }
        }

        private void Initialize(int id, SpeciesModel speciesModel, PlanetModel planetModel, VehicleModel vehicleModel, string name, int age)
        {
            Id = id;
            SpeciesModel = speciesModel;
            PlanetModel = planetModel;
            VehicleModel = vehicleModel;
            Name = name;
            Age = age;
        }

        public int Id { get; set; }

        public SpeciesModel SpeciesModel { get; set; }

        public PlanetModel PlanetModel { get; set; }

        public VehicleModel VehicleModel { get; set; }

        public string Name { get; set; }

        public int Age { get; set; }

        public LifeformModel CreateLifeform()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id > 0 ||
                SpeciesModel.Id <= 0 ||
                PlanetModel.Id <= 0 ||
                string.IsNullOrEmpty(Name) ||
                Age <= 0)             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             Lifeform addTarget = new Lifeform();             addTarget.SpeciesId = SpeciesModel.Id;             addTarget.PlanetId = PlanetModel.Id;             addTarget.Name = Name;             addTarget.Age = Age;             if (VehicleModel.Id > 0)
            {
                addTarget.VehicleId = VehicleModel.Id;
            }

            dataContext.Lifeforms.InsertOnSubmit(addTarget);

            try
            {
                dataContext.SubmitChanges();
                Id = addTarget.Id;
                HistoryModel.CreateHistoryRecord(callingMethod, $"Created [Lifeform] with Id: {Id}");
            }
            catch (Exception exception)
            {
                Logger.LogException(callingMethod, exception);
                HistoryModel.CreateHistoryRecord(callingMethod, $"Create [Lifeform] failed. Error: {exception.Message}");
                return null;
            }

            return this;
        }

        public LifeformModel DeleteLifeform()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0)             {                 Logger.LogError(callingMethod, "The Id must be greater than 0.");                 return null;             }             Lifeform deleteTarget = dataContext.Lifeforms                 .SingleOrDefault(v => v.Id == Id);

            if (deleteTarget != null)
            {
                dataContext.Lifeforms.DeleteOnSubmit(deleteTarget);

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Deleted [Lifeform] with Id: {Id}");
                    Id = 0;
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Delete [Lifeform] failed. Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public LifeformModel UpdateLifeform()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0 ||
                SpeciesModel.Id <= 0 ||
                PlanetModel.Id <= 0 ||
                string.IsNullOrEmpty(Name) ||
                Age <= 0)             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             Lifeform updateTarget = dataContext.Lifeforms                 .SingleOrDefault(v => v.Id == Id);

            if (updateTarget != null)
            {
                updateTarget.SpeciesId = SpeciesModel.Id;
                updateTarget.PlanetId = PlanetModel.Id;
                updateTarget.Name = Name;
                updateTarget.Age = Age;

                if(VehicleModel.Id > 0)
                {
                    updateTarget.VehicleId = VehicleModel.Id;
                }
                else
                {
                    updateTarget.VehicleId = null;
                }

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Updated [Lifeform] with Id: {Id}");
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Update [Lifeform] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public static IEnumerable<LifeformModel> ReadLifeforms()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Lifeforms.ToLifeformModelCollection().OrderBy(v => v.Id);
        }
    }
}

namespace KitchenSinkDLL
{
    public static partial class Extensions
    {
        public static IEnumerable<LifeformModel> ToLifeformModelCollection(this IQueryable<Lifeform> lifeforms)
        {
            List<LifeformModel> returnCollection = new List<LifeformModel>();

            if (lifeforms != null)
            {
                string callingMethod = MethodBase.GetCurrentMethod().Name;
                KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

                IEnumerable<SpeciesModel> speciesRecords = dataContext.Species.ToSpeciesModelCollection();
                IEnumerable<PlanetModel> planets = dataContext.Planets.ToPlanetModelCollection();
                IEnumerable<VehicleModel> vehicles = dataContext.Vehicles.ToVehicleModelCollection();

                foreach (var lifeform in lifeforms)
                {
                    SpeciesModel speciesModel = speciesRecords.FirstOrDefault(s => s.Id == lifeform.SpeciesId);
                    PlanetModel planetModel = planets.FirstOrDefault(p => p.Id == lifeform.PlanetId);
                    VehicleModel vehicleModel = vehicles.FirstOrDefault(v => v.Id == lifeform.VehicleId);

                    if(vehicleModel == null)
                    {
                        vehicleModel = new VehicleModel();
                    }

                    LifeformModel newModel = new LifeformModel(
                        lifeform.Id, 
                        speciesModel,
                        planetModel,
                        vehicleModel,
                        lifeform.Name,
                        lifeform.Age);
                    returnCollection.Add(newModel);
                }
            }

            return returnCollection;
        }
    }
}

Logger Class:

using System;

namespace KitchenSinkDLL
{
    public class Logger
    {
        public static void LogMessage(string callingMethod, string message)
        {
            Console.WriteLine($"{DateTime.Now}: CallingMethod: {callingMethod}");
            Console.WriteLine($"{DateTime.Now}:     Msg      : {message}");
        }

        public static void LogError(string callingMethod, string errorMessage)
        {
            Console.WriteLine($"{DateTime.Now}: CallingMethod: {callingMethod}");
            Console.WriteLine($"{DateTime.Now}:     Error    : {errorMessage}");
        }

        public static void LogException(string callingMethod, Exception exception)
        {
            Console.WriteLine($"{DateTime.Now}: CallingMethod : {callingMethod}");
            Console.WriteLine($"{DateTime.Now}: Exception     : {exception.GetType().Name}");
            Console.WriteLine($"{DateTime.Now}:     Message   : {exception.Message}");
            Console.WriteLine($"{DateTime.Now}:     Source    : {exception.Source}");
            Console.WriteLine($"{DateTime.Now}:     StackTrace: {exception.StackTrace}");
        }
    }
}

PlanetModel Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace KitchenSinkDLL.Models
{
    public class PlanetModel
    {
        public PlanetModel()
        {
            Initialize(0, string.Empty);
        }

        public PlanetModel(string name)
        {
            Initialize(0, name);
        }

        public PlanetModel(int id)
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            Planet planet = dataContext.Planets
                .SingleOrDefault(p => p.Id == id);

            if (planet != null)
            {
                Initialize(planet.Id, planet.Name);
            }
            else
            {
                Initialize(0, string.Empty);
            }
        }

        public PlanetModel(Planet planet)
        {
            if(planet != null)
            {
                Initialize(planet.Id, planet.Name);
            }
            else
            {
                Initialize(0, string.Empty);
            }
        }

        private void Initialize(int id, string name)
        {
            Id = id;
            Name = name;
        }

        public int Id { get; set; }

        public string Name { get; set; }

        public PlanetModel CreatePlanet()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id > 0 ||
                string.IsNullOrEmpty(Name))
            {
                Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");
                return null;
            }

            Planet addTarget = new Planet();
            addTarget.Name = Name;
            dataContext.Planets.InsertOnSubmit(addTarget);

            try
            {
                dataContext.SubmitChanges();
                Id = addTarget.Id;
                HistoryModel.CreateHistoryRecord(callingMethod, $"Created [Planet] with Id: {Id}");
            }
            catch (Exception exception)
            {
                Logger.LogException(callingMethod, exception);
                HistoryModel.CreateHistoryRecord(callingMethod, $"Create [Planet] failed.  Error: {exception.Message}");
                return null;
            }

            return this;
        }

        public PlanetModel DeletePlanet()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0)             {                 Logger.LogError(callingMethod, "The Id must be greater than 0.");                 return null;             }             Planet deleteTarget = dataContext.Planets                 .SingleOrDefault(p => p.Id == Id);

            if (deleteTarget != null)
            {
                dataContext.Planets.DeleteOnSubmit(deleteTarget);

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Deleted [Planet] with Id: {Id}");
                    Id = 0;
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Delete [Planet] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public PlanetModel UpdatePlanet()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0 ||                 string.IsNullOrEmpty(Name))             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             Planet updateTarget = dataContext.Planets                 .SingleOrDefault(p => p.Id == Id);

            if (updateTarget != null)
            {
                updateTarget.Name = Name;

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Updated [Planet] with Id: {Id}");
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Update [Planet] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public static IEnumerable<PlanetModel> ReadPlanets()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Planets.ToPlanetModelCollection().OrderBy(p => p.Id);
        }
    }
}

namespace KitchenSinkDLL
{
    public static partial class Extensions
    {
        public static IEnumerable<PlanetModel> ToPlanetModelCollection(this IQueryable<Planet> planets)
        {
            List<PlanetModel> returnCollection = new List<PlanetModel>();

            if (planets != null)
            {
                foreach (var planet in planets)
                {
                    PlanetModel newModel = new PlanetModel(planet);
                    returnCollection.Add(newModel);
                }
            }

            return returnCollection;
        }
    }
}

SpeciesModel Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace KitchenSinkDLL.Models
{
    public class SpeciesModel
    {
        public SpeciesModel()
        {
            Initialize(0, string.Empty);
        }

        public SpeciesModel(string name)
        {
            Initialize(0, name);
        }

        public SpeciesModel(int id)
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            Specy specy = dataContext.Species
                .SingleOrDefault(s => s.Id == id);

            if (specy != null)
            {
                Initialize(specy.Id, specy.Name);
            }
            else
            {
                Initialize(0, string.Empty);
            }
        }

        public SpeciesModel(Specy specy)
        {
            if(specy != null)
            {
                Initialize(specy.Id, specy.Name);
            }
            else
            {
                Initialize(0, string.Empty);
            }
        }

        private void Initialize(int id, string name)
        {
            Id = id;
            Name = name;
        }

        public int Id { get; set; }

        public string Name { get; set; }

        public SpeciesModel CreateSpecies()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id > 0 ||
                string.IsNullOrEmpty(Name))
            {
                Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");
                return null;
            }

            Specy addTarget = new Specy();
            addTarget.Name = Name;
            dataContext.Species.InsertOnSubmit(addTarget);

            try
            {
                dataContext.SubmitChanges();
                Id = addTarget.Id;
                HistoryModel.CreateHistoryRecord(callingMethod, $"Created [Species] with Id: {Id}");
            }
            catch (Exception exception)
            {
                Logger.LogException(callingMethod, exception);
                HistoryModel.CreateHistoryRecord(callingMethod, $"Create [Species] failed.  Error: {exception.Message}");
                return null;
            }

            return this;
        }

        public SpeciesModel DeleteSpecies()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0)             {                 Logger.LogError(callingMethod, "The Id must be greater than 0.");                 return null;             }             Specy deleteTarget = dataContext.Species                 .SingleOrDefault(s => s.Id == Id);

            if (deleteTarget != null)
            {
                dataContext.Species.DeleteOnSubmit(deleteTarget);

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Deleted [Species] with Id: {Id}");
                    Id = 0;
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Delete [Species] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public SpeciesModel UpdateSpecies()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0 ||                 string.IsNullOrEmpty(Name))             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             Specy updateTarget = dataContext.Species                 .SingleOrDefault(s => s.Id == Id);

            if (updateTarget != null)
            {
                updateTarget.Name = Name;

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Updated [Species] with Id: {Id}");
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Update [Species] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public static IEnumerable<SpeciesModel> ReadPlanets()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Species.ToSpeciesModelCollection().OrderBy(s => s.Id);
        }
    }
}

namespace KitchenSinkDLL
{
    public static partial class Extensions
    {
        public static IEnumerable<SpeciesModel> ToSpeciesModelCollection(this IQueryable<Specy> speciesRecords)
        {
            List<SpeciesModel> returnCollection = new List<SpeciesModel>();

            if (speciesRecords != null)
            {
                foreach (var species in speciesRecords)
                {
                    SpeciesModel newModel = new SpeciesModel(species);
                    returnCollection.Add(newModel);
                }
            }

            return returnCollection;
        }
    }
}

VehicleModel Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace KitchenSinkDLL.Models
{
    public class VehicleModel
    {
        public VehicleModel()
        {
            Initialize(0, new EngineModel(), string.Empty, string.Empty, 0, 0, 0);
        }

        public VehicleModel(int engineId, string make, string model, int year, int wheelCount, int passengerCapacity)
        {
            Initialize(0, new EngineModel(engineId), make, model, year, wheelCount, passengerCapacity);
        }

        public VehicleModel(EngineModel engineModel, string make, string model, int year, int wheelCount, int passengerCapacity)
        {
            Initialize(0, engineModel, make, model, year, wheelCount, passengerCapacity);
        }

        public VehicleModel(int id, EngineModel engineModel, string make, string model, int year, int wheelCount, int passengerCapacity)
        {
            Initialize(id, engineModel, make, model, year, wheelCount, passengerCapacity);
        }
        public VehicleModel(int id)
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            Vehicle vehicle = dataContext.Vehicles
                .SingleOrDefault(v => v.Id == id);

            if (vehicle != null)
            {
                Initialize(vehicle.Id, new EngineModel(vehicle.Engine), vehicle.Make, vehicle.Model, vehicle.Year, vehicle.WheelCount, vehicle.PassengerCapacity);
            }
            else
            {
                Initialize(0, new EngineModel(), string.Empty, string.Empty, 0, 0, 0);
            }
        }

        public VehicleModel(Vehicle vehicle)
        {
            if (vehicle != null)
            {
                Initialize(vehicle.Id, new EngineModel(vehicle.Engine), vehicle.Make, vehicle.Model, vehicle.Year, vehicle.WheelCount, vehicle.PassengerCapacity);
            }
            else
            {
                Initialize(0, new EngineModel(), string.Empty, string.Empty, 0, 0, 0);
            }
        }

        private void Initialize(int id, EngineModel engineModel, string make, string model, int year, int wheelCount, int passengerCapacity)
        {
            Id = id;
            EngineModel = engineModel;
            Make = make;
            Model = model;
            Year = year;
            WheelCount = wheelCount;
            PassengerCapacity = passengerCapacity;
        }

        public int Id { get; set; }

        public EngineModel EngineModel { get; set; }

        public string Make { get; set; }

        public string Model { get; set; }

        public int Year { get; set; }

        public int WheelCount { get; set; }

        public int PassengerCapacity { get; set; }

        public VehicleModel CreateVehicle()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id > 0 ||
                EngineModel.Id <= 0 ||
                string.IsNullOrEmpty(Make) ||
                string.IsNullOrEmpty(Model) ||
                Year <= 0 ||
                WheelCount <= 0 ||
                PassengerCapacity <= 0)
            {
                Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");
                return null;
            }

            Vehicle addTarget = new Vehicle();
            addTarget.EngineId = EngineModel.Id;
            addTarget.Make = Make;
            addTarget.Model = Model;
            addTarget.Year = Year;
            addTarget.WheelCount = WheelCount;
            addTarget.PassengerCapacity = PassengerCapacity;
            dataContext.Vehicles.InsertOnSubmit(addTarget);

            try
            {
                dataContext.SubmitChanges();
                Id = addTarget.Id;
                HistoryModel.CreateHistoryRecord(callingMethod, $"Created [Vehicle] with Id: {Id}");
            }
            catch (Exception exception)
            {
                Logger.LogException(callingMethod, exception);
                HistoryModel.CreateHistoryRecord(callingMethod, $"Create [Vehicle] failed.  Error: {exception.Message}");
                return null;
            }

            return this;
        }

        public VehicleModel DeleteVehicle()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0)             {                 Logger.LogError(callingMethod, "The Id must be greater than 0.");                 return null;             }             Vehicle deleteTarget = dataContext.Vehicles                 .SingleOrDefault(v => v.Id == Id);

            if (deleteTarget != null)
            {
                dataContext.Vehicles.DeleteOnSubmit(deleteTarget);

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Deleted [Vehicle] with Id: {Id}");
                    Id = 0;
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Delete [Vehicle] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public VehicleModel UpdateVehicle()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);

            if (Id <= 0 ||
                EngineModel.Id <= 0 ||
                string.IsNullOrEmpty(Make) ||
                string.IsNullOrEmpty(Model) ||
                Year <= 0 ||
                WheelCount <= 0 ||
                PassengerCapacity <= 0)             {                 Logger.LogError(callingMethod, "One of the properties is null, empty, or invalid.");                 return null;             }             Vehicle updateTarget = dataContext.Vehicles                 .SingleOrDefault(v => v.Id == Id);

            if (updateTarget != null)
            {
                updateTarget.EngineId = EngineModel.Id;
                updateTarget.Make = Make;
                updateTarget.Model = Model;
                updateTarget.Year = Year;
                updateTarget.WheelCount = WheelCount;
                updateTarget.PassengerCapacity = PassengerCapacity;

                try
                {
                    dataContext.SubmitChanges();
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Updated [Vehicle] with Id: {Id}");
                }
                catch (Exception exception)
                {
                    Logger.LogException(callingMethod, exception);
                    HistoryModel.CreateHistoryRecord(callingMethod, $"Update [Vehicle] failed.  Error: {exception.Message}");
                    return null;
                }
            }
            else
            {
                Logger.LogError(callingMethod, $"No record for the Id: {Id}");
                return null;
            }

            return this;
        }

        public static IEnumerable<VehicleModel> ReadVehicles()
        {
            string callingMethod = MethodBase.GetCurrentMethod().Name;
            KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
            return dataContext.Vehicles.ToVehicleModelCollection().OrderBy(v => v.Id);
        }
    }
}

namespace KitchenSinkDLL
{
    public static partial class Extensions
    {
        public static IEnumerable<VehicleModel> ToVehicleModelCollection(this IQueryable<Vehicle> vehicles)
        {
            List<VehicleModel> returnCollection = new List<VehicleModel>();

            if (vehicles != null)
            {
                string callingMethod = MethodBase.GetCurrentMethod().Name;
                KitchenSinkLinqToSqlDataContext dataContext = KitchenSinkDLL.CreateDataContext(callingMethod);
                IEnumerable<EngineModel> engines = dataContext.Engines.ToEngineModelCollection();

                foreach (var vehicle in vehicles)
                {
                    EngineModel engineModel = engines.FirstOrDefault(e => e.Id == vehicle.EngineId);
                    VehicleModel newModel = new VehicleModel(
                        vehicle.Id, 
                        engineModel,
                        vehicle.Model,
                        vehicle.Model,
                        vehicle.Year,
                        vehicle.WheelCount,
                        vehicle.PassengerCapacity);
                    returnCollection.Add(newModel);
                }
            }

            return returnCollection;
        }
    }
}

 

KitchenSinkClogger Program:

This isn’t anything special…it just fills the database up with random junk to use for showing data.  You may get some relational errors if it randomly tries to insert the same record twice…but it’s ok to just ignore them and let it fill the database up with whatever.

Program Class:

using KitchenSinkDLL.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace KitchenSinkClogger
{
    public class Program
    {
        static void Main(string[] args)
        {
            Random rnd = new Random(DateTime.Now.Millisecond);
            KitchenSinkDLL.KitchenSinkDLL.ConnectionString = @"Data Source=cmd-roswell;Initial Catalog=KitchenSink;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            for(int i = 0; i < 1000000; i++)
            {
                EngineModel newEngineModel = new EngineModel($"{rnd.Next(i)}EngineMake{rnd.Next(i)}", rnd.Next(1, 12), $"Disp{rnd.Next(1, 10000)}", rnd.Next(1, 1200));
                newEngineModel.CreateEngine();

                List<EngineModel> engines = EngineModel.ReadEngines().ToList();
                EngineModel engine = engines[rnd.Next(engines.Count - 1)];
                VehicleModel newVehicleModel = new VehicleModel(engine, $"{rnd.Next(i)}Make{rnd.Next(i)}", $"{rnd.Next(i)}Model{rnd.Next(i)}", rnd.Next(1, 2016), rnd.Next(2, 18), rnd.Next(1, 8));
                newVehicleModel.CreateVehicle();

                PlanetModel newPlanetModel = new PlanetModel($"{rnd.Next(i)}Planet{rnd.Next(i)}");
                newPlanetModel.CreatePlanet();

                SpeciesModel newSpeciesModel = new SpeciesModel($"{rnd.Next(i)}Species{rnd.Next(i)}");
                newSpeciesModel.CreateSpecies();

                List<PlanetModel> planets = PlanetModel.ReadPlanets().ToList();
                PlanetModel planet = planets[rnd.Next(planets.Count - 1)];
                List<SpeciesModel> speciesRecords = SpeciesModel.ReadPlanets().ToList();
                SpeciesModel species = speciesRecords[rnd.Next(speciesRecords.Count - 1)];

                VehicleModel vehicle = null;

                if(rnd.Next(i) > i / 2)
                {
                    List<VehicleModel> vehicles = VehicleModel.ReadVehicles().ToList();
                    vehicle = vehicles[rnd.Next(vehicles.Count - 1)];
                }

                LifeformModel newLifeformModel = new LifeformModel(species, planet, vehicle, $"{rnd.Next(i)}Lifeform{rnd.Next(i)}", rnd.Next(1, 200));
                newLifeformModel.CreateLifeform();
            }
        }
    }
}

 

That’s pretty much it for now.  I’ll be adding a MVC and WPF app into the project later.  Also feel free to critque the projects I’ve got…I’m always open to advice about how I’m doing stuff.  🙂  Enjoy!

Advertisements
ExampleAppinator

One thought on “ExampleAppinator

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s