-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeController.cs
97 lines (84 loc) · 2.93 KB
/
HomeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Hass_Alarm.Models;
using Microsoft.Extensions.Configuration;
using HADotNet.Core.Clients;
using Hass_Alarm.Views.Home;
using HADotNet.Core;
using System.Net;
using Hass_Alarm.Data;
namespace Hass_Alarm.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IConfiguration _configuration;
private readonly ApplicationDbContext _dbContext;
private readonly IAlarmState _alarmState;
string Entity_Arm = "";
string Entity_ArmHome = "";
public HomeController(ILogger<HomeController> logger, IConfiguration configuration, Data.ApplicationDbContext dbContext, IAlarmState alarmState)
{
_logger = logger;
_configuration = configuration;
_dbContext = dbContext;
_alarmState = alarmState;
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
var model = new PanelModel();
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public async Task<IActionResult> Panel()
{
var model = new PanelModel();
model.ArmState = await _alarmState.GetArmState();
model.State = model.ArmState.ToString().ToLower();
return View(model);
}
[ValidateAntiForgeryToken, HttpPost]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public async Task<IActionResult> Panel(PanelModel model)
{
if (!string.IsNullOrEmpty(model.code))
{
var pin = _dbContext.PinCodes.Where(o => o.Pin == model.code);
if (pin.Any())
{
model.code_invalid = false;
switch (model.action)
{
case "arm":
break;
case "disarm":
break;
case "arm_home":
break;
case "unlock":
break;
default:
break;
}
}
else
model.code_invalid = true;
}
return Json(model);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}