2019-04-14 11:55:05 -04:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2019-03-30 23:04:15 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore;
|
2019-04-11 21:43:05 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2019-04-14 11:55:05 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-04-11 21:43:05 -04:00
|
|
|
|
using WebfrontCore.ViewModels;
|
2019-03-30 23:04:15 -04:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
2019-04-14 11:55:05 -04:00
|
|
|
|
[Authorize]
|
2019-03-30 23:04:15 -04:00
|
|
|
|
public class ConfigurationController : BaseController
|
|
|
|
|
{
|
2019-12-02 16:52:36 -05:00
|
|
|
|
public ConfigurationController(IManager manager) : base (manager)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 23:04:15 -04:00
|
|
|
|
public IActionResult Edit()
|
|
|
|
|
{
|
2019-07-27 09:18:49 -04:00
|
|
|
|
if (Client.Level < SharedLibraryCore.Database.Models.EFClient.Permission.Owner)
|
2019-04-16 12:32:42 -04:00
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 23:04:15 -04:00
|
|
|
|
return View("Index", Manager.GetApplicationSettings().Configuration());
|
|
|
|
|
}
|
2019-04-11 21:43:05 -04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2019-04-14 11:55:05 -04:00
|
|
|
|
public async Task<IActionResult> Edit(ApplicationConfiguration newConfiguration, bool addNewServer = false, bool shouldSave = false)
|
2019-04-11 21:43:05 -04:00
|
|
|
|
{
|
2019-07-27 09:18:49 -04:00
|
|
|
|
if (Client.Level < SharedLibraryCore.Database.Models.EFClient.Permission.Owner)
|
2019-04-16 12:32:42 -04:00
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
if (shouldSave)
|
2019-04-12 23:25:18 -04:00
|
|
|
|
{
|
2019-04-14 11:55:05 -04:00
|
|
|
|
var currentConfiguration = Manager.GetApplicationSettings().Configuration();
|
2019-04-12 23:25:18 -04:00
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
var newConfigurationProperties = newConfiguration.GetType().GetProperties();
|
|
|
|
|
foreach (var property in currentConfiguration.GetType().GetProperties())
|
2019-04-12 23:25:18 -04:00
|
|
|
|
{
|
2019-04-14 11:55:05 -04:00
|
|
|
|
var newProp = newConfigurationProperties.First(_prop => _prop.Name == property.Name);
|
|
|
|
|
var newPropValue = newProp.GetValue(newConfiguration);
|
|
|
|
|
|
|
|
|
|
if (newPropValue != null && newProp.CanWrite)
|
|
|
|
|
{
|
|
|
|
|
property.SetValue(currentConfiguration, newPropValue);
|
|
|
|
|
}
|
2019-04-12 23:25:18 -04:00
|
|
|
|
}
|
2019-04-14 11:55:05 -04:00
|
|
|
|
|
|
|
|
|
await Manager.GetApplicationSettings().Save();
|
2019-04-12 23:25:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
if (addNewServer)
|
|
|
|
|
{
|
|
|
|
|
newConfiguration.Servers.Add(new ServerConfiguration());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-04-12 23:25:18 -04:00
|
|
|
|
return View("Index", newConfiguration);
|
2019-04-11 21:43:05 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult GetNewListItem(string propertyName, int itemCount)
|
|
|
|
|
{
|
2019-04-16 12:32:42 -04:00
|
|
|
|
if (Client.Level != SharedLibraryCore.Database.Models.EFClient.Permission.Owner)
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 21:43:05 -04:00
|
|
|
|
var configInfo = new ConfigurationInfo()
|
|
|
|
|
{
|
2019-04-14 11:55:05 -04:00
|
|
|
|
NewItemCount = itemCount,
|
|
|
|
|
PropertyName = propertyName
|
2019-04-11 21:43:05 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PartialView("_ListItem", configInfo);
|
|
|
|
|
}
|
2019-03-30 23:04:15 -04:00
|
|
|
|
}
|
|
|
|
|
}
|