42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace EntityFrameworkBasics.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
public IActionResult Index()
|
|
{
|
|
// No using statement because of the DI and IoC
|
|
var context = IoC.ApplicationDbContext;
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
if (!context.Settings.Any())
|
|
{
|
|
context.Settings.Add(new SettingsDataModel
|
|
{
|
|
Name = "BackgroundColor",
|
|
Value = "Red"
|
|
});
|
|
|
|
var SettingsLocally = context.Settings.Local.Count();
|
|
var SettingsDatabase = context.Settings.Count();
|
|
|
|
var firstLocal = context.Settings.Local.FirstOrDefault();
|
|
var firstDatabase = context.Settings.FirstOrDefault();
|
|
|
|
context.SaveChanges();
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
public IActionResult Error()
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
}
|