Exemplo 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);
        }
Exemplo n.º 2
0
        private void CreateTimeSlots(object state)
        {
            var scope     = _scopeFactory.CreateScope();
            var dbContext = scope.ServiceProvider.GetRequiredService <UULContext>();
            var newSlots  = TimeSlotsFactory.CreateTodayTimeSlots(dbContext, 11);

            newSlots.Wait();
            dbContext.TimeSlots.AddRange(newSlots.Result);
            int rows = dbContext.SaveChanges();

            _logger.LogInformation("Creation func affected " + rows + " rows, run at " + DateOperations.Now().ToString());
            scope.Dispose();
        }