55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace EntityFrameworkBasics.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
|
|
#region Protected members
|
|
|
|
protected ApplicationDBContext context;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Default constructor
|
|
/// </summary>
|
|
/// <param name="_context">the injected context</param>
|
|
public HomeController(ApplicationDBContext _context)
|
|
{
|
|
context = _context;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|