Ejemplo n.º 1
0
        public static void CreateDummyData(UULContext context)
        {
            for (int i = 0; i < 20; i++)
            {
                var user = new NewUserDTO()
                {
                    Login = "******" + i, AvatarSrc = "Default", Name = "Inhabitant_" + i, ApartmentCode = "T" + i, Pwd = "12345"
                };
                UserDao.AddFromDto(context, user);
            }
            context.SaveChanges();
            List <TimeSlot> timeSlots = new();
            var             today     = DateTime.UtcNow;

            for (int i = 0; i < 3; i++)
            {
                var slots = TimeSlotsFactory.CreateTimeSlotsForDateUTC(context, new DateTime(today.Year, today.Month, today.Day - i).ToUniversalTime(), 5);
                slots.Wait();
                timeSlots.AddRange(slots.Result);
            }
            var habitants = context.Habitants.ToList();
            var size      = habitants.Count;
            var rnd       = new Random();

            foreach (TimeSlot timeSlot in timeSlots)
            {
                for (int i = 0; i < rnd.Next(4); i++)
                {
                    if (timeSlot.OccupiedBy == null)
                    {
                        timeSlot.OccupiedBy = new List <Habitant>();
                    }
                    timeSlot.OccupiedBy.Add(habitants.ElementAt(rnd.Next(size)));
                }
            }
            context.TimeSlots.AddRange(timeSlots);

            var newsList = new List <News>();

            for (int i = 0; i < 5; i++)
            {
                newsList.Add(new News()
                {
                    Title = "Title " + i, Content = " Content " + i + dummyContent, Author = "Dummy data generator", CreatedAt = DateTime.UtcNow, Auditory = Auditory.GUESTS, NewsType = NewsType.INFO
                });
            }
            newsList.Add(new News()
            {
                Title = "Title Registered", Content = " Content Registered", Author = "Dummy data generator", CreatedAt = DateTime.UtcNow, Auditory = Auditory.REGISTERED, NewsType = NewsType.CALL_TO_ACTION
            });
            newsList.Add(new News()
            {
                Title = "Title Activated", Content = " Content Activated", Author = "Dummy data generator", CreatedAt = DateTime.UtcNow, Auditory = Auditory.ACTIVATED, NewsType = NewsType.ALERT
            });
            context.News.AddRange(newsList);
        }
Ejemplo n.º 2
0
        public static void Initialize(UULContext context, IConfiguration config)
        {
            if (config.GetValue <bool>("DropDataOnStart") == true)
            {
                context.Database.EnsureDeleted();
            }
            context.Database.EnsureCreated();
            if (!context.Users.Any())
            {
                context.Users.Add(SecHelper.CreateDefaultAdmin());
            }
            if (!context.Rules.Any())
            {
                context.Towers.RemoveRange(context.Towers);
                context.SpecialFloors.RemoveRange(context.SpecialFloors);
                context.BannedApartments.RemoveRange(context.BannedApartments);
                context.Gyms.RemoveRange(context.Gyms);

                var towers = new List <Tower>()
                {
                    new Tower()
                    {
                        Name = "A", FloorsCount = 10
                    },
                    new Tower()
                    {
                        Name = "B", FloorsCount = 10
                    },
                    new Tower()
                    {
                        Name = "C", FloorsCount = 12
                    },
                    new Tower()
                    {
                        Name = "D", FloorsCount = 12
                    }
                };

                var specialFloors = new List <SpecialFloor>()
                {
                    new SpecialFloor()
                    {
                        Name = "A10", Alias = "PH"
                    },
                    new SpecialFloor()
                    {
                        Name = "B10", Alias = "PH"
                    },
                    new SpecialFloor()
                    {
                        Name = "C12", Alias = "PH"
                    },
                    new SpecialFloor()
                    {
                        Name = "D12", Alias = "PH"
                    },
                };

                var gyms = new List <Gym>()
                {
                    new Gym()
                    {
                        Name = "A", IsOpen = true
                    },
                    new Gym()
                    {
                        Name = "B", IsOpen = true
                    }
                };

                context.Towers.AddRange(towers);
                context.SpecialFloors.AddRange(specialFloors);
                context.Gyms.AddRange(gyms);

                var rules = new Rules()
                {
                    Version               = 0,
                    PersonsPerTimeSlot    = 4,
                    HabitantsPerApartment = 4,
                    DoorsPerFloor         = 8,
                    TimeSlotSpan          = DefaultTimeSlotSpan,
                    Towers           = towers,
                    SpecialFloors    = specialFloors,
                    BannedApartments = { },
                    Gyms             = gyms
                };

                context.Rules.Add(rules);
                context.SaveChanges();
            }
            if (config.GetValue <bool>("CreateDummyDataOnStart") == false)
            {
                var newSlots = TimeSlotsFactory.CreateTodayTimeSlots(context, 11); // 11 Utc is 5 am at Gdl
                newSlots.Wait();
                context.TimeSlots.AddRange(newSlots.Result);
            }
            else
            {
                DummyDataFactory.CreateDummyData(context);
            }
            context.SaveChanges();
        }