Example #1
0
        /// <summary>
        /// Insert the standard Value to the db
        /// </summary>
        private static void InserStandarData()
        {
            Console.WriteLine("adding StandrdData");
            using (var dataList = new HFABDataList())
            {
                var locations = new[] { "0101", "0102", "0103", "0201", "0202", "0301", "0302", "VAKT", "SOPRUM", "TVÄTT" };
                var events    = new[] { "DÖUT", "DÖIN", "FDIN", "FDUT" };
                var doorNames = new[] { "LGH0101", "LGH0102", "LGH0103", "LGH0201", "LGH0202", "LGH0301", "LGH0302", "BLK0101", "BLK0102", "BLK0103", "BLK0201", "BLK0202", "BLK0301", "BLK0302", "VAKT", "SOPRUM", "TVÄTT", "UT" };

                foreach (var location in locations)

                {
                    dataList.Locations.Add(new Models.Location {
                        Name = location
                    });
                    dataList.SaveChanges();
                }
                foreach (var eventCode in events)
                {
                    dataList.Events.Add(new Models.Event {
                        Code = eventCode
                    });
                    dataList.SaveChanges();
                }
                foreach (var doorName in doorNames)
                {
                    dataList.DoorNames.Add(new Models.DoorName {
                        Name = doorName
                    });
                    dataList.SaveChanges();
                }

                var persons = new[, ]
                {
                    { "Liam", "Jönsson", "0101A", "1" },
                    { "Elias", "Petterson", "0102A", "2" }, { "Wilma", "Johansson", "0102B", "2" },
                    { "Alicia", "Sanchez", "0103A", "3" }, { "Aaron", "Sanchez", "0103B", "3" },
                    { "Olivia", "Erlander", "0201A", "4" }, { "William", "Erlander", "0201B", "4" }, { "Alexander", "Erlander", "0201C", "4" }, { "Astrid", "Erlander", "0201D", "4" },
                    { "Lucas", "Adolfsson", "0202A", "5" }, { "Ebba", "Adolfsson", "0202B", "5" }, { "Lilly", "Adolfsson", "0202C", "5" },
                    { "Ella", "Ahlström", "0301A", "6" }, { "Alma", "Alfredsson", "0301B", "6" }, { "Elsa", "Ahlström", "0301C", "6" }, { "Maja", "Ahlström", "0301D", "6" },
                    { "Noah", "Almgren", "0302A", "7" }, { "Adam", "Andersen", "0302B", "7" }, { "Kattis", "Backman", "0302C", "7" }, { "Oscar", "Chen", "0302D", "7" },
                    { "Vaktmästare", "", "VAKT01", "8" }
                };
                for (int i = 0; i < persons.GetLength(0); i++)
                {
                    dataList.Persons.Add(new Models.Person
                    {
                        FirstName = persons[i, 0],
                        LastName  = persons[i, 1],
                        Tag       = persons[i, 2],
                        Location  = dataList.Locations.FirstOrDefault(l => l.ID == int.Parse(persons[i, 3]))
                    });
                    dataList.SaveChanges();
                }
            }
            Console.WriteLine("Standrad data done");
        }
Example #2
0
        /// <summary>
        /// cheack if data need to be added
        /// </summary>
        public static void CheackIfDataExist()
        {
            using (var dataList = new HFABDataList())
            {
                Console.WriteLine("Check if data need to be added to DB");
                var standardDataList = dataList.Persons.Take(2).ToList();
                var DemonDataList    = dataList.Loggs.Take(2).ToList();
                if (standardDataList.Count == 0)
                {
                    InserStandarData();
                }
                if (DemonDataList.Count == 0)
                {
                    DemonData();
                }

                Console.Clear();
            }
        }