public async Task SaveSiteNotification([FromBody][Required] string siteNotification) { SiteNotice notice = _db.SiteNotice.First(); notice.Content = siteNotification; await _db.SaveChangesAsync(); }
public SiteNoticeVM(SiteNotice bo) { Id = bo.Id; Name = bo.Name; Description = bo.Description; Publisher = bo.Publisher; CreateTime = bo.CreateTime; }
/// <summary> /// 处理公告的图片上传 /// </summary> /// <param name="entity"></param> private async Task <bool> UploadNoticeIMG(SiteNotice entity) { try { var images = Request.Form.Files; if (images.Count() > 0) { foreach (var image in images) { if (image != null) { var currImageName = image.FileName; var timeForFile = (DateTime.Now.ToString("yyyyMMddHHmmss") + "-").Trim(); string extensionName = currImageName.Substring(currImageName.LastIndexOf(".")); var imageName = ContentDispositionHeaderValue .Parse(image.ContentDisposition) .FileName .Trim('"') .Substring(image.FileName.LastIndexOf("\\") + 1); var newImageName = timeForFile + Guid.NewGuid() + extensionName; var boPath = "../../images/UploadImages/" + ImageType.Notices.ToString() + "/" + newImageName; var imagePath = _hostingEnv.WebRootPath + $@"\images\UploadImages\{ImageType.Notices.ToString()}"; imageName = _hostingEnv.WebRootPath + $@"\images\UploadImages\{ImageType.Notices.ToString()}\{newImageName}"; Directory.CreateDirectory(imagePath); //创建目录 using (FileStream fs = System.IO.File.Create(imageName)) { image.CopyTo(fs); fs.Flush(); } var noticeIMG = new BusinessImage { Name = newImageName, DisplayName = currImageName, OriginalFileName = currImageName, Description = "站点公告图片", RelevanceObjectId = entity.Id, UploaderId = Guid.Empty, UploadPath = boPath, PhysicalPath = imageName, FileSize = image.Length, Type = ImageType.Notices }; await _businessImage.AddOrEditAndSaveAsyn(noticeIMG); } } return(true); } return(false); } catch (Exception) { return(false); } }
public async Task <IActionResult> CreateSiteNotice(SiteNoticeVM input) { if (string.IsNullOrEmpty(input.Name) || string.IsNullOrEmpty(input.Description)) { return(Json(new { result = false, message = "必填项为空,请检查标题和内容是否已经选择和填写!" })); } var siteNotice = new SiteNotice { Publisher = GetUser(), Name = EncodeFilterHelper.EncodeHtml(input.Name), Description = EncodeFilterHelper.EncodeHtml(input.Description) }; var r = await _siteNotice.AddOrEditAndSaveAsyn(siteNotice); if (r) { await UploadNoticeIMG(siteNotice); return(Json(new { result = true })); } return(Json(new { result = false, message = "发布失败,请重试!" })); }