@*******************************************************************************************************
// Companies.cshtml - Gbtc
//
// Copyright © 2016, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 01/15/2016 - J. Ritchie Carroll
// Generated original version of source code.
//
//*****************************************************************************************************@
@using System.Net.Http
@using GSF.Configuration
@using GSF.Data.Model
@using GSF.Security
@using GSF.Web
@using GSF.Web.Model
@using GSF.Web.Shared
@using GSF.Web.Shared.Model
@inherits ExtendedTemplateBase
@section StyleSheets {
}
@{
HttpRequestMessage request = ViewBag.Request;
DataContext dataContext = ViewBag.DataContext;
bool userIsAdmin = UserIsAdmin();
ViewBag.Title = "Companies";
ViewBag.ShowSearchFilter = true;
CategorizedSettingsSection configurationSettings = ConfigurationFile.Current.Settings;
CategorizedSettingsElement setting;
CategorizedSettingsElementCollection systemSettings = configurationSettings["systemSettings"];
setting = systemSettings["CompanyAcronym"];
string companyAcronym = setting == null || string.IsNullOrWhiteSpace(setting.Value) ? "GPA" : setting.Value;
CategorizedSettingsElementCollection securityProvider = configurationSettings["securityProvider"];
setting = securityProvider["ApplicationName"];
string applicationName = setting == null || string.IsNullOrWhiteSpace(setting.Value) ? "TSF Service" : setting.Value;
if (ViewBag.IsPost && userIsAdmin)
{
PostData postData = request.GetPostData();
string selectedCompanyID = postData.FormData["selectedCompanyID"];
int companyID;
if (int.TryParse(selectedCompanyID, out companyID))
{
TableOperations companyTable = dataContext.Table();
Company company = companyTable.QueryRecordWhere("ID = {0}", companyID);
if (company != null)
{
systemSettings["CompanyName"].Value = company.Name;
systemSettings["CompanyAcronym"].Value = company.Acronym;
if (ViewBag.Model != null && ViewBag.Model.Global != null)
{
ViewBag.Model.Global.CompanyName = company.Name;
ViewBag.Model.Global.CompanyAcronym = company.Acronym;
}
companyAcronym = company.Acronym;
ConfigurationFile.Current.Save();
}
}
}
ViewBag.HeaderColumns = new[]
{ // { "Field", "Label", "Classes" }
new[] { "Acronym", "Acronym", "text-left" },
new[] { "Name", "Name", "text-left" },
new[] { null, "Configured
Company", "text-center valign-middle" },
new[] { "URL", "URL", "text-left" }
};
ViewBag.BodyRows = BodyRows(applicationName, userIsAdmin.ToString().ToLower()).ToString();
ViewBag.AddNewEditDialog = AddNewEditDialog(dataContext).ToString();
}
@functions {
public bool UserIsAdmin()
{
SecurityPrincipal securityPrincipal = ViewBag.SecurityPrincipal as SecurityPrincipal;
if ((object)securityPrincipal == null)
return false;
return securityPrincipal.IsInRole("Administrator");
}
}
@helper BodyRows(string applicationName, string userIsAdmin)
{
|
|
|
|
|
}
@helper AddNewEditDialog(DataContext dataContext)
{
@Raw(dataContext.AddInputField("Acronym", initialFocus: true))
@Raw(dataContext.AddInputField("Name"))
@Raw(dataContext.AddInputField("MapAcronym"))
@Raw(dataContext.AddInputField("URL", "url"))
@Raw(dataContext.AddInputField("LoadOrder", "number", "Load Order"))
}
@Html.RenderResource("GSF.Web.Model.Views.PagedViewModel.cshtml")
@if (userIsAdmin) {
}
@section Scripts {
}@{
ViewBag.StyleSheetsSection = RenderSection("StyleSheets").ToString();
ViewBag.ScriptsSection = RenderSection("Scripts").ToString();
}