| | |
| | | using System.Collections.Generic; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Web.Mvc; |
| | | using CommonHelper; |
| | | using CommonHelper.Format; |
| | | using GasolineBlend.Entity; |
| | | using Pissa.Service.DbService; |
| | | using Quartz.Util; |
| | | using SqlSugar; |
| | | |
| | | namespace GasolineBlend.Controllers |
| | |
| | | var res = _countryService.GetEcoindustryTree(); |
| | | return SuccessNoShow(data: res); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取轮播图 |
| | | /// </summary> |
| | | /// <param name="isDisplay">是否展示</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public ActionResult GetCarouselImg(bool? isDisplay = null) |
| | | { |
| | | var res = _countryService.Context.Queryable<SysCarouselImg>() |
| | | .WhereIF(isDisplay != null, a => a.IsDisplay == isDisplay) |
| | | .OrderBy(a => a.Sort) |
| | | .ToList(); |
| | | return Success(data: res); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传轮播图 |
| | | /// </summary> |
| | | /// <param name="imgName"></param> |
| | | /// <param name="sort"></param> |
| | | /// <param name="isDisplay"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public ActionResult AddCarouselImg(string imgName, int sort = 0, bool isDisplay = true) |
| | | { |
| | | var file = Request.Files["img"]; |
| | | if (file == null) |
| | | return Error("请上传文件"); |
| | | if (imgName.IsNullOrWhiteSpace()) |
| | | imgName = file.FileName; |
| | | if (!Directory.Exists(Server.MapPath("/CarouselImg"))) |
| | | Directory.CreateDirectory(Server.MapPath("/CarouselImg")); |
| | | string filePath = $"/CarouselImg/{Guid.NewGuid()}{Path.GetExtension(file.FileName)}"; |
| | | string absolutePath = Server.MapPath(filePath); |
| | | file.SaveAs(absolutePath); |
| | | |
| | | var model = new SysCarouselImg() |
| | | { |
| | | Name = imgName, |
| | | Sort = sort, |
| | | IsDisplay = isDisplay, |
| | | CreateUserId = OperatorProvider.Instance?.Current?.UserId??"0", |
| | | Url = filePath |
| | | }; |
| | | var res = _countryService.Context.Insertable(model).ExecuteReturnIdentity(); |
| | | return Success(data: res); |
| | | } |
| | | /// <summary> |
| | | /// 修改 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <param name="imgName"></param> |
| | | /// <param name="sort"></param> |
| | | /// <param name="isDisplay"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public ActionResult UpdateCarouselImg(int id,string imgName, int? sort = null, bool? isDisplay = null) |
| | | { |
| | | var res = _countryService.Context.Updateable<SysCarouselImg>() |
| | | .SetColumns(a => new SysCarouselImg() { UpdateTime = DateTime.Now}) |
| | | .SetColumnsIF(!string.IsNullOrWhiteSpace(imgName),a=>a.Name==imgName) |
| | | .SetColumnsIF(sort!=null,a=>a.Sort==(int)sort) |
| | | .SetColumnsIF(isDisplay != null,a=>a.IsDisplay == (bool)isDisplay) |
| | | .Where(a => a.Id == id) |
| | | .ExecuteCommand(); |
| | | return Success(); |
| | | } |
| | | /// <summary> |
| | | /// 删除 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public ActionResult DeleteCarouselImg(int id) |
| | | { |
| | | var img = _countryService.Context.Queryable<SysCarouselImg>() |
| | | .Where(a => a.Id == id) |
| | | .First(); |
| | | if (img == null) |
| | | return Error("找不到该图片"); |
| | | |
| | | var res = _countryService.Context.Deleteable<SysCarouselImg>() |
| | | .Where(a => a.Id == id) |
| | | .ExecuteCommand(); |
| | | System.IO.File.Delete(Server.MapPath(img.Url)); |
| | | return res > 0 ? Success() : Error(); |
| | | } |
| | | } |
| | | } |