コード例 #1
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Desk.Add(Desk);
            _context.SaveChanges();
            Quote.DeskID = Desk.ID;
            Quote.Date   = DateTime.Now;
            _context.DeskQuote.Add(Quote);
            _context.SaveChanges();

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            _context.Attach(Desk).State = EntityState.Modified;
            Quote.DeskID = Desk.ID;
            _context.Attach(Quote).State = EntityState.Modified;
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeskExists(Desk.ID) || !QuoteExists(Quote.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new MegaDeskDBContext(
                serviceProvider.GetRequiredService <DbContextOptions <MegaDeskDBContext> >()))
     {
         // Look for any movies.
         if (!context.Rush.Any())
         {
             context.Rush.AddRange(
                 new Rush
             {
                 days        = 0,
                 priceLarge  = 0,
                 priceMedium = 0,
                 priceSmall  = 0,
             },
                 new Rush
             {
                 days        = 3,
                 priceLarge  = 60,
                 priceMedium = 70,
                 priceSmall  = 80,
             },
                 new Rush
             {
                 days        = 5,
                 priceLarge  = 40,
                 priceMedium = 50,
                 priceSmall  = 60,
             },
                 new Rush
             {
                 days        = 7,
                 priceLarge  = 30,
                 priceMedium = 35,
                 priceSmall  = 40,
             }
                 );
         }
         if (!context.Material.Any())
         {
             context.Material.AddRange(
                 new Material
             {
                 cost = 200,
                 type = "Oak",
             },
                 new Material
             {
                 cost = 100,
                 type = "Laminate",
             },
                 new Material
             {
                 cost = 50,
                 type = "Pine",
             },
                 new Material
             {
                 cost = 300,
                 type = "Rosewood",
             },
                 new Material
             {
                 cost = 125,
                 type = "Veneer",
             }
                 );
         }
         context.SaveChanges();
     }
 }