/// <summary> /// 获取所有的公告 /// </summary> /// <returns></returns> public async Task <List <SiteNoticeVM> > GetSiteNotices() { var siteNoticesVM = new List <SiteNoticeVM>(); var attachments = new List <BusinessImage>(); var query = await _siteNotice.GetAllIncludingAsyn(x => x.Publisher); var siteNotices = query.OrderByDescending(x => x.CreateTime); var queryImgs = await _businessImage.GetAllAsyn(); foreach (var siteNotice in siteNotices) { var siteNoticeVM = new SiteNoticeVM(siteNotice); if (queryImgs.Count() > 0) { attachments = queryImgs.Where(x => x.RelevanceObjectId == siteNotice.Id).ToList(); if (attachments.Count() > 0) { siteNoticeVM.Attachments = attachments; } else { siteNoticeVM.Attachments = new List <BusinessImage>(); } siteNoticeVM.OrderNumber = (siteNoticesVM.Count() + 1).ToString(); } else { siteNoticeVM.Attachments = new List <BusinessImage>(); } siteNoticesVM.Add(siteNoticeVM); } return(siteNoticesVM); }
/// <summary> /// 获取公告内容(视图模型) /// </summary> /// <param name="id"></param> /// <returns></returns> private async Task <SiteNoticeVM> GetSiteNoticeVM(Guid id) { var attachments = new List <BusinessImage>(); var query = await _siteNotice.GetAllIncludingAsyn(x => x.Publisher); var siteNotice = query.FirstOrDefault(x => x.Id == id); var siteNoticeVM = new SiteNoticeVM(siteNotice); var queryImgs = await _businessImage.GetAllAsyn(); if (queryImgs.Count() > 0) { attachments = queryImgs.Where(x => x.RelevanceObjectId == siteNotice.Id).ToList(); if (attachments.Count() > 0) { siteNoticeVM.Attachments = attachments; } else { siteNoticeVM.Attachments = attachments; } } else { siteNoticeVM.Attachments = attachments; } return(siteNoticeVM); }
/// 获取所有的公告 /// </summary> /// <returns></returns> public async Task <IActionResult> SiteNotices() { var siteNoticesVM = new List <SiteNoticeVM>(); var query = await _siteNotice.GetAllListAsyn(); var siteNotices = query.OrderByDescending(x => x.CreateTime); foreach (var siteNotice in siteNotices) { var siteNoticeVM = new SiteNoticeVM(siteNotice); siteNoticeVM.OrderNumber = (siteNoticesVM.Count() + 1).ToString(); siteNoticesVM.Add(siteNoticeVM); } return(View(siteNoticesVM)); }
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 = "发布失败,请重试!" })); }