/// <summary> /// 删除数据 /// </summary> /// <param name="theData">删除的数据</param> public async Task <ActionResult> DeleteArticelFile(int attachmentId, string path) { PageActionResult operateResult = new PageActionResult(); int result = 0; if (attachmentId > 0) { result = _attachmentBusiness.Delete(m => m.Id == attachmentId); if (result > 0) { RestApiClient restApiClient = new RestApiClient(Vars.FILESTORE_SITE); await restApiClient.AddAuthorization(Vars.IDENTITYSERVER_SITE + "/connect/token"); operateResult = restApiClient.Post <PageActionResult>("/api/FileHandler/DeleteArticelFile", new { savePath = path }); } } else { RestApiClient restApiClient = new RestApiClient(Vars.FILESTORE_SITE); await restApiClient.AddAuthorization(Vars.IDENTITYSERVER_SITE + "/connect/token"); operateResult = restApiClient.Post <PageActionResult>("/api/FileHandler/DeleteArticelFile", new { savePath = path }); } if (operateResult != null) { if (operateResult.Result == PageActionResultType.Failed) { return(Error(operateResult.Message)); } } return(Success(operateResult.Data)); }
/// <summary> /// 保存 /// </summary> /// <param name="theData">保存的数据</param> public ActionResult SaveData(ArticleDto theData) { if (!string.IsNullOrEmpty(theData.Cover)) { theData.Cover = theData.Cover.Substring(theData.Cover.IndexOf("/Upload")); } Article article = _mapper.Map <ArticleDto, Article>(theData);//进行Dto对象与模型之间的映射 if (theData.Id == 0) { article.CreateTime = DateTime.Now; _articleBusiness.Insert(article); } else { _articleBusiness.Update(article); _attachmentBusiness.Delete(m => m.TargetId == article.Id); } List <string> attachments = new List <string>(); if (!string.IsNullOrEmpty(theData.Attachments)) { attachments = theData.Attachments.Split(',').CastToList <string>(); } List <Attachment> attachmentList = new List <Attachment>(); attachments.ForEach(m => { var data = m.Split('&'); Attachment attach = new Attachment(); attach.Directory = data[0]; attach.SavePath = data[1].Substring(data[1].IndexOf("/Upload")); attach.Thumb = data[2].Substring(data[1].IndexOf("/Upload")); attach.FileExt = Path.GetExtension(data[1]); attach.Name = data[3]; attach.Type = 1; attach.TargetId = article.Id; attach.CreateTime = DateTime.Now; attach.Store = 0; attachmentList.Add(attach); }); if (attachmentList.Count > 0) { _attachmentBusiness.BulkInsert(attachmentList); } return(Success()); }
public virtual JsonResult Delete(int id) => Json(_attachmentBusiness.Delete(id));