123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using System;
- using System.IO;
- using System.Linq;
- using FMSAdmin.Data;
- using FMSAdmin.Entities;
- using FMSAdmin.Helpers;
- using FMSAdmin.Models;
- using FMSAdmin.Services;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using OfficeOpenXml;
- namespace FMSAdmin.Controllers {
- [Authorize]
- [ApiController]
- [ApiVersion("1")]
- [Route("api/[controller]")]
- public class SiteConfigController : Controller {
- private readonly ILogger<SiteConfigController> _logger;
- private readonly FMSContext _context;
- private readonly StorageHelper _storageHelper;
- public SiteConfigController(
- ILogger<SiteConfigController> logger,
- StorageHelper storageHelper,
- FMSContext context
- ) {
- _logger = logger;
- _storageHelper = storageHelper;
- _context = context;
- }
-
-
-
- [HttpPost("[action]")]
- public IActionResult SaveModule(SiteConfig data) {
- var persist = _context.SiteConfig.Single();
- persist.UseWorkAutoOrder = data.UseWorkAutoOrder;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/facility/ExecutionSchedule", !data.UseWorkAutoOrder);
- _SetMenuVisible(SitemapType.현장, "/facility/ExecutionSchedule", !data.UseWorkAutoOrder);
- _SetMenuVisible(SitemapType.모바일, "/Facility/ExecutionSchedule", !data.UseWorkAutoOrder);
- _SetMenuVisible(SitemapType.본사, "/facility/ExecutionScheduleCalendar", !data.UseWorkAutoOrder);
- _SetMenuVisible(SitemapType.현장, "/facility/ExecutionScheduleCalendar", !data.UseWorkAutoOrder);
- persist.UseWorkAutoResult = data.UseWorkAutoResult;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/facility/WorkExecution", !data.UseWorkAutoResult);
- _SetMenuVisible(SitemapType.현장, "/facility/WorkExecution", !data.UseWorkAutoResult);
- _SetMenuVisible(SitemapType.모바일, "/Facility/WorkWait", !data.UseWorkAutoResult);
- persist.UseMaterialBuyAutoApproval = data.UseMaterialBuyAutoApproval;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialPurchaseRequestApproval", !data.UseMaterialBuyAutoApproval);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialPurchaseRequestApproval", !data.UseMaterialBuyAutoApproval);
- persist.UseMaterialStoredAutoApproval = data.UseMaterialStoredAutoApproval;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialStoredApproval", !data.UseMaterialStoredAutoApproval);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialStoredApproval", !data.UseMaterialStoredAutoApproval);
- persist.UseMaterialAdjustmentAutoApproval = data.UseMaterialAdjustmentAutoApproval;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialReleaseApproval", !data.UseMaterialAdjustmentAutoApproval);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialReleaseApproval", !data.UseMaterialAdjustmentAutoApproval);
- persist.UseMaterialMonlthlyStock = data.UseMaterialMonlthlyStock;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialMonthlyStock", data.UseMaterialMonlthlyStock);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialMonthlyStock", data.UseMaterialMonlthlyStock);
- _SetMenuVisible(SitemapType.모바일, "/material/MaterialMonthlyStock", data.UseMaterialMonlthlyStock);
- persist.UseMaterialType = data.UseMaterialType;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialCodeType", data.UseMaterialType);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialCodeType", data.UseMaterialType);
- persist.UseMaterialReasonableStockCount = data.UseMaterialReasonableStockCount;
- persist.UseMaterialShortStock = data.UseMaterialShortStock;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialShortStock", data.UseMaterialShortStock);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialShortStock", data.UseMaterialShortStock);
- persist.UseEquipmentRent = data.UseEquipmentRent;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/equipment/Rent", data.UseEquipmentRent);
- _SetMenuVisible(SitemapType.현장, "/equipment/Rent", data.UseEquipmentRent);
- persist.UseEquipmentCurrent = data.UseEquipmentCurrent;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/equipment/StatusInfo", data.UseEquipmentCurrent);
- _SetMenuVisible(SitemapType.현장, "/equipment/StatusInfo", data.UseEquipmentCurrent);
- persist.UsePartnerCode = data.UsePartnerCode;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/contract/ContractClass", data.UsePartnerCode);
- _SetMenuVisible(SitemapType.현장, "/contract/ContractClass", data.UsePartnerCode);
- persist.UseServicePartner = data.UseServicePartner;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/contract/ServicePartner", data.UseServicePartner);
- _SetMenuVisible(SitemapType.현장, "/contract/ServicePartner", data.UseServicePartner);
- _context.SaveChanges();
- persist.UseMaterialPurchaseOrder = data.UseMaterialPurchaseOrder;
-
-
-
- _SetMenuVisible(SitemapType.본사, "/material/MaterialPurchaseOrder", !data.UseMaterialPurchaseOrder);
- _SetMenuVisible(SitemapType.현장, "/material/MaterialPurchaseOrder", !data.UseMaterialPurchaseOrder);
- _context.SaveChanges();
-
-
-
- persist.UseWorkProcess = data.UseWorkProcess;
- _SetMenuVisible(SitemapType.본사, "/facility/CurrentWork", data.UseWorkProcess);
- _SetMenuVisible(SitemapType.현장, "/facility/CurrentWork", data.UseWorkProcess);
- _SetMenuVisible(SitemapType.모바일, "/Facility/WorkProcess", data.UseWorkProcess);
- _SetMenuVisible(SitemapType.본사, "/facility/WorkApproval", data.UseWorkProcess);
- _SetMenuVisible(SitemapType.현장, "/facility/WorkApproval", data.UseWorkProcess);
- _SetMenuVisible(SitemapType.모바일, "/Facility/WorkComplete", data.UseWorkProcess);
- _SetMenuVisible(SitemapType.본사, "/facility/WorkComplete", !data.UseWorkProcess);
- _SetMenuVisible(SitemapType.현장, "/facility/WorkComplete", !data.UseWorkProcess);
- _SetMenuVisible(SitemapType.모바일, "/Facility/WorkProcessAndComplete", !data.UseWorkProcess);
- _context.SaveChanges();
- return Ok(persist);
- }
-
-
-
- [HttpPost("[action]")]
- public IActionResult SaveLogo(SiteConfig data) {
- if (!string.IsNullOrEmpty(data.WebLoginLogo)) {
- _storageHelper.Move(data.WebLoginLogo, "/static/login_logo.png");
- }
- if (!string.IsNullOrEmpty(data.WebLoginBackground)) {
- _storageHelper.Move(data.WebLoginBackground, "/static/login_bg.jpg");
- }
- if (!string.IsNullOrEmpty(data.WebLoginFMSLogo)) {
- _storageHelper.Move(data.WebLoginFMSLogo, "/static/login_fms_logo.png");
- }
- if (!string.IsNullOrEmpty(data.WebMainLogo)) {
- _storageHelper.Move(data.WebMainLogo, "/static/logo.png");
- }
- if (!string.IsNullOrEmpty(data.WebCopyrightLogo)) {
- _storageHelper.Move(data.WebCopyrightLogo, "/static/copyright.png");
- }
- if (!string.IsNullOrEmpty(data.AppLoginLogo)) {
- _storageHelper.Move(data.AppLoginLogo, "/static/app_login_logo.png");
- }
- if (!string.IsNullOrEmpty(data.AppMainLogo)) {
- _storageHelper.Move(data.AppMainLogo, "/static/app_logo.png");
- }
- return Ok(data);
- }
-
-
-
- [HttpGet]
- public IActionResult Get() {
- var config = _context.SiteConfig.Single();
- return Ok(config);
- }
-
-
-
- private void _SetMenuVisible(SitemapType type, string path, bool visible) {
- var menu = (from x in _context.Sitemap
- where x.Type == type && x.Path.ToLower() == path.ToLower()
- select x).FirstOrDefault();
- if (menu != null) {
- _logger.LogInformation("menu.Name: " + menu.Name);
- _logger.LogInformation("menu.Path: " + menu.Path);
- _logger.LogInformation("menu.Hidden: " + !visible);
- menu.Hidden = !visible;
- _logger.LogInformation("menu.Hidden: " + menu.Hidden);
- }
- }
- }
- }
|