protected void SaveShowTimes_Click(object sender, EventArgs e) { // Demo grabbing all the data from the ListView control // to build a List<MovieShowTime> objects. // A ListView stores all its data inside the .Items property. List <MovieShowTime> theData = new List <MovieShowTime>(); foreach (ListViewDataItem data in MovieShowTimesListView.Items) { // I need to "find" the asp.net controls that hold my data HiddenField hiddenShowTimeId = // Find and do a "safe cast" data.FindControl("ShowTimeIdField") as HiddenField; Calendar startTimeCalendar = data.FindControl("StartTime") as Calendar; DropDownList roomDropDown = data.FindControl("RoomDropDown") as DropDownList; // To be save, check that we found the controls if (hiddenShowTimeId != null && startTimeCalendar != null && roomDropDown != null) { var info = new MovieShowTime { ShowTimeId = int.Parse(hiddenShowTimeId.Value), StartTime = startTimeCalendar.SelectedDate, TheaterId = int.Parse(roomDropDown.SelectedValue) }; theData.Add(info); } } // end of loop MessageBox.Text = $"I found {theData.Count} items"; }
private static void SeedEverything(MoviegramDbContext context) { context.Database.EnsureCreated(); //If db already initialized do not seed anything if (context.Movies.Any()) { return; } //This will help to generate same random data Randomizer.Seed = new Random(1); var testMovies = new Faker <Movie>() .RuleFor(o => o.Id, f => f.Random.Guid()) .RuleFor(o => o.Genre, f => f.Lorem.Paragraphs()) .RuleFor(o => o.Title, f => $"{f.Lorem.Sentence(3)}") .RuleFor(o => o.Poster, (f, o) => f.Image.PlaceholderUrl(1024, 1024, o.Title, f.Internet.Color().Replace("#", ""))); var testCelebrities = new Faker <Celebrity>() .RuleFor(u => u.Id, f => f.Random.Guid()) .RuleFor(u => u.Name, f => $"{f.Name.FirstName()} {f.Name.LastName()}") .RuleFor(u => u.ProfilePhoto, f => f.Internet.Avatar()); var celebrities = testCelebrities.Generate(100); context.Celebrities.AddRange(celebrities); var movies = testMovies.Generate(100); var random = new Random(); //Assign actors to movies foreach (var movie in movies) { //Take max 10 random actor and make a movie var actorCount = random.Next(10); var tempActors = celebrities.OrderBy(r => Guid.NewGuid()).Take(actorCount).ToList(); foreach (var celebrity in tempActors) { movie.Actors.Add(new MovieCelebrity { CelebrityId = celebrity.Id, MovieId = movie.Id }); } var movieTimes = random.Next(60, 180); var startTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 9, 0, 0); var tempTime = startTime; //Add showTimes to movies do { var tempShowTime = new MovieShowTime { Id = Guid.NewGuid(), ShowTimeStart = tempTime, ShowTimeEnd = tempTime.AddMinutes(movieTimes) }; movie.MovieShowTimes.Add(tempShowTime); tempTime = tempTime.AddMinutes(movieTimes + 30); } while (tempTime < startTime.AddHours(9)); context.Movies.Add(movie); } context.SaveChanges(); }
public static MovieShowTimeViewModel FromEntity(MovieShowTime entity) { return(entity == null ? new MovieShowTimeViewModel() : Projection.Compile().Invoke(entity)); }