using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using AngleSharp.Html.Parser;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Bot.Builder.Integration.AspNet.Core;
|
using Microsoft.Extensions.Logging;
|
using Newtonsoft.Json;
|
using System.Net.Http;
|
using System.Threading.Tasks;
|
using zhengcaioa.Models;
|
using zhengcaioa.IService;
|
using CommonToolsCore;
|
using Services;
|
using System.IO;
|
using Microsoft.AspNetCore.Hosting;
|
using Grpc.Core;
|
|
namespace zhengcaioa.Controllers.settings
|
{
|
[CheckLogin]
|
public class SystemsettingController : Controller
|
{
|
private readonly ILogger<SystemsettingController> _logger;
|
private readonly ISystemsettingService _systemsettingService;
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
private readonly ISysAttachmentService _sysAttachmentService;
|
|
|
public SystemsettingController(ILogger<SystemsettingController> logger, ISystemsettingService systemsettingService, IWebHostEnvironment hostingEnvironment, ISysAttachmentService sysAttachmentService)
|
{
|
_logger = logger;
|
_systemsettingService = systemsettingService;
|
_hostingEnvironment = hostingEnvironment;
|
_sysAttachmentService = sysAttachmentService;
|
}
|
|
|
public IActionResult Edit(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
SystemsettingDTO dto = new SystemsettingDTO();
|
dto = _systemsettingService.Get(id);
|
|
ViewData.Model = dto;
|
return View();
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">系统设置对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public IActionResult Save(SystemsettingDTO data)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
data.RecStatus = "A";
|
if (String.IsNullOrEmpty(data.Id))
|
{
|
data.Creater = curentuser.Id;
|
data.Createtime = DateTime.Now;
|
}
|
data.Modifier = curentuser.Id;
|
data.Modifytime = DateTime.Now;
|
|
ResultEntity resultEntity = _systemsettingService.save(data);
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">系统设置对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public async Task<IActionResult> fileUpAsync()
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = true;
|
resultEntity.Message = "";
|
IFormFile[] files = HttpContext.Request.Form.Files.ToArray();
|
//long size = files.Sum(f => f.Length);
|
string webRootPath = _hostingEnvironment.WebRootPath;
|
// string contentRootPath = _hostingEnvironment.ContentRootPath;
|
|
|
var filePathsave = @"\UploadingFiles\" + DateTime.Now.ToString("yyyyMMdd") + @"\";
|
var filePath = webRootPath + filePathsave;
|
// 判断文件的存在
|
if (Directory.Exists(filePath))
|
{
|
//存在文件
|
}
|
else
|
{
|
//不存在文件
|
Directory.CreateDirectory(filePath);//创建该文件
|
}
|
|
int i = 0;
|
foreach (var formFile in files)
|
{
|
filePath += formFile.FileName;
|
resultEntity.Message += filePathsave + formFile.FileName;
|
if(i!= files.Length - 1)
|
{
|
resultEntity.Message += ",";
|
}
|
if (formFile.Length > 0)
|
{
|
using (var stream = new FileStream(filePath, FileMode.Create))
|
{
|
await formFile.CopyToAsync(stream);
|
}
|
}
|
i++;
|
}
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
|
/// <summary>
|
/// 上传文件通用
|
/// </summary>
|
/// <param name="data">系统设置对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public IActionResult fileUpTongYong()
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
|
ResultEntity<SysAttachment> resultEntity = new ResultEntity<SysAttachment>();
|
resultEntity.Result = true;
|
List<SysAttachment> sysAttachments = new List<SysAttachment>();
|
|
IFormFile[] files = HttpContext.Request.Form.Files.ToArray();
|
//long size = files.Sum(f => f.Length);
|
string webRootPath = _hostingEnvironment.WebRootPath;
|
// string contentRootPath = _hostingEnvironment.ContentRootPath;
|
|
|
var filePathsave = @"\UploadingFiles\" + DateTime.Now.ToString("yyyyMMdd") + @"\";
|
var filePath = webRootPath + filePathsave;
|
// 判断文件的存在
|
if (Directory.Exists(filePath))
|
{
|
//存在文件
|
}
|
else
|
{
|
//不存在文件
|
Directory.CreateDirectory(filePath);//创建该文件
|
}
|
|
int i = 0;
|
foreach (var formFile in files)
|
{
|
string fileExtName = Path.GetExtension(formFile.FileName);
|
string fileName = Guid.NewGuid().ToString().Replace("-", "")+ fileExtName;
|
|
//resultEntity.Message += filePathsave + fileName; //formFile.FileName;
|
//resultEntity.ReturnID += formFile.FileName;
|
//if (i != files.Length - 1)
|
//{
|
// resultEntity.Message += ",";
|
// resultEntity.ReturnID += ",";
|
//}
|
sysAttachments.Add(new SysAttachment() { Filefullname = formFile.FileName ,Filepath = filePathsave + fileName });
|
if (formFile.Length > 0)
|
{
|
using (var stream = new FileStream(filePath + fileName, FileMode.Create))
|
{
|
formFile.CopyTo(stream);
|
stream.Flush();
|
}
|
}
|
i++;
|
}
|
resultEntity.DataList = sysAttachments;
|
return new JsonResult(resultEntity);
|
}
|
|
|
|
|
|
|
/// <summary>
|
/// 上传文件通用
|
/// </summary>
|
/// <param name="data">系统设置对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public IActionResult fileUpremove(string id)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = true;
|
resultEntity = _sysAttachmentService.ModifyStatus(id, curentuser.Id);
|
|
|
|
return new JsonResult(resultEntity);
|
}
|
|
}
|
}
|