Пример #1
0
        public void PopulateHomieLinks()
        {
            foreach (var homie in _context.Homies
                     .Include(x => x.CheckIns)
                     .Include(x => x.CheckOuts)
                     .Include(x => x.Location))
            {
                if (homie.CheckIns.Count == 0)
                {
                    homie.CheckIns = CreateRandomCheckIns(homie, 5);
                }

                if (homie.CheckOuts.Count == 0)
                {
                    homie.CheckOuts = CreateRandomCheckOuts(homie, 5);
                }

                if (homie?.Location == null)
                {
                    int maxId = _context.Locations.Max(x => x.Id);
                    int minId = _context.Locations.Min(x => x.Id);
                    homie.Location = _context.Locations
                                     .First(x => x.Id == SeedDefaults.GetRandomInt(minId, maxId + 1));
                }
            }

            _context.SaveChanges();
        }
Пример #2
0
        public Location CreateRandomLocation()
        {
            var street = SeedDefaults.Streets[SeedDefaults.GetRandomInt()];
            var temp   = new Location
            {
                Street      = street,
                HouseNumber = SeedDefaults.GetRandomDigitString(),
                AreaCode    = SeedDefaults.GetRandomDigitString(),
                City        = SeedDefaults.Streets[SeedDefaults.GetRandomInt()],
                State       = SeedDefaults.States[SeedDefaults.GetRandomInt()],
                DisplayName = street + SeedDefaults.GetRandomInt(max: 1000)
            };

            return(temp);
        }
Пример #3
0
        public static DateTime GetRandomDateTime()
        {
            var monthsOffset  = SeedDefaults.GetRandomInt(-12, 1);
            var daysOffset    = SeedDefaults.GetRandomInt(-30, 1);
            var hoursOffset   = SeedDefaults.GetRandomInt(-60, 1);
            var minutesOffset = SeedDefaults.GetRandomInt(-60, 1);
            var secondsOffset = SeedDefaults.GetRandomInt(-60, 1);

            var time = DateTime.Now
                       .AddMonths(monthsOffset)
                       .AddDays(daysOffset)
                       .AddHours(hoursOffset)
                       .AddMinutes(minutesOffset)
                       .AddSeconds(secondsOffset);

            return(time);
        }
Пример #4
0
        public Homie CreateRandomHomie()
        {
            var isHome    = SeedDefaults.GetRandomBool();
            var firstName = SeedDefaults.FirstNames[SeedDefaults.GetRandomInt()];

            var temp = new Homie
            {
                FirstName = firstName,
                LastName  = SeedDefaults.LastNames[SeedDefaults.GetRandomInt()],
                Email     = SeedDefaults.Emails[SeedDefaults.GetRandomInt()],
                IsHome    = isHome,
                // HasGuest can only be true if the Homie is home, otherwise
                // it will always be false
                HasGuest = isHome ? SeedDefaults.GetRandomBool() : false,
                NickName = firstName.ToLower() + SeedDefaults.GetRandomInt(max: 100)
            };

            return(temp);
        }