-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathHomeController.cs
More file actions
98 lines (82 loc) · 2.92 KB
/
HomeController.cs
File metadata and controls
98 lines (82 loc) · 2.92 KB
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
98
using Grand.Business.Core.Interfaces.Authentication;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Directory;
using Microsoft.AspNetCore.Mvc;
namespace Grand.Web.Vendor.Controllers;
public class HomeController : BaseVendorController
{
#region Ctor
public HomeController(
ILogger<HomeController> logger,
IGrandAuthenticationService authenticationService)
{
_logger = logger;
_authenticationService = authenticationService;
}
#endregion
#region Fields
private readonly ILogger<HomeController> _logger;
private readonly IGrandAuthenticationService _authenticationService;
#endregion
#region Methods
public IActionResult Index()
{
return View();
}
public IActionResult Statistics()
{
return View();
}
public IActionResult AccessDenied()
{
_logger.LogInformation("Access denied");
return View();
}
public async Task<IActionResult> Logout()
{
await _authenticationService.SignOut();
return RedirectToRoute("VendorLogin");
}
[AcceptVerbs("Get")]
public async Task<IActionResult> GetStatesByCountryId(
[FromServices] ICountryService countryService,
[FromServices] ITranslationService translationService,
string countryId, bool? addSelectStateItem, bool? addAsterisk)
{
// This action method gets called via an ajax request
if (string.IsNullOrEmpty(countryId))
return Json(new List<dynamic>
{ new { id = "", name = translationService.GetResource("Address.SelectState") } });
var country = await countryService.GetCountryById(countryId);
var states = country != null ? country.StateProvinces.ToList() : new List<StateProvince>();
var result = (from s in states
select new { id = s.Id, name = s.Name }).ToList();
if (addAsterisk.HasValue && addAsterisk.Value)
{
//asterisk
result.Insert(0, new { id = "", name = "*" });
}
else
{
if (country == null)
{
//country is not selected ("choose country" item)
if (addSelectStateItem.HasValue && addSelectStateItem.Value)
result.Insert(0,
new { id = "", name = translationService.GetResource("Vendor.Address.SelectState") });
}
else
{
//some country is selected
if (result.Any())
//country has some states
if (addSelectStateItem.HasValue && addSelectStateItem.Value)
result.Insert(0,
new { id = "", name = translationService.GetResource("Vendor.Address.SelectState") });
}
}
return Json(result);
}
#endregion
}