コード例 #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name,Station")] ConcertLocation concertLocation)
        {
            if (id != concertLocation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(concertLocation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ConcertLocationExists(concertLocation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(concertLocation));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Station")] ConcertLocation concertLocation)
        {
            if (ModelState.IsValid)
            {
                concertLocation.Id = Guid.NewGuid();
                _context.Add(concertLocation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(concertLocation));
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: PimVendrig/MagicCarpet
        private void PrepareDatabase(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
                using (var context = serviceScope.ServiceProvider.GetRequiredService <MagicCarpetWebAppContext>())
                {
                    context.Database.Migrate();

                    if (!context.ConcertLocations.Any())
                    {
                        //Seed
                        var ziggoDome = new ConcertLocation {
                            Name = "Ziggo Dome", Station = "ASB"
                        };
                        var afasLive = new ConcertLocation {
                            Name = "AFAS Live", Station = "ASB"
                        };
                        var gelredome = new ConcertLocation {
                            Name = "Gelredome", Station = "AH"
                        };

                        context.ConcertLocations.Add(ziggoDome);
                        context.ConcertLocations.Add(afasLive);
                        context.ConcertLocations.Add(gelredome);

                        var nickiAug1Concert = new ConcertInfo {
                            Name = "Nicki Minaj (Aug 1st)", Location = ziggoDome, Date = new DateTime(2018, 08, 1, 22, 0, 0)
                        };
                        context.ConcertInfoes.Add(nickiAug1Concert);
                        context.ConcertInfoes.Add(new ConcertInfo {
                            Name = "Nicki Minaj (Aug 2nd)", Location = ziggoDome, Date = new DateTime(2018, 08, 2, 22, 0, 0)
                        });
                        context.ConcertInfoes.Add(new ConcertInfo {
                            Name = "Justin Bieber (Aug 3rd)", Location = afasLive, Date = new DateTime(2018, 08, 3, 22, 0, 0)
                        });
                        context.ConcertInfoes.Add(new ConcertInfo {
                            Name = "Justin Bieber (Aug 4th)", Location = afasLive, Date = new DateTime(2018, 08, 4, 22, 0, 0)
                        });
                        context.ConcertInfoes.Add(new ConcertInfo {
                            Name = "Snow Patrol (Aug 5th)", Location = gelredome, Date = new DateTime(2018, 08, 5, 22, 0, 0)
                        });

                        context.Reservations.Add(new Reservation {
                            Concert = nickiAug1Concert, Destination = "HGV", Amount = 6, EmailAddress = "*****@*****.**", Agrees = true, PaymentDetails = "{\"id\": \"493900A6-64AD-41CA-B569-A3364BBA62CA\",\"success\": true}"
                        });
                        context.Reservations.Add(new Reservation {
                            Concert = nickiAug1Concert, Destination = "HGV", Amount = 2, EmailAddress = "*****@*****.**", Agrees = true, PaymentDetails = "{\"id\": \"493900A6-64AD-41CA-B569-A3364BBA62CB\",\"success\": true}"
                        });

                        context.SaveChanges();
                    }

                    if (context.ConcertInfoes.All(c => c.Image == null))
                    {
                        foreach (var concert in context.ConcertInfoes)
                        {
                            if (concert.Name.StartsWith("Nicki"))
                            {
                                concert.Image = "Nicki.jpg";
                            }
                            else if (concert.Name.StartsWith("Justin"))
                            {
                                concert.Image = "Justin.jpg";
                            }
                            else if (concert.Name.StartsWith("Snow"))
                            {
                                concert.Image = "Snow.jpg";
                            }
                        }

                        context.SaveChanges();
                    }
                }
        }