/// <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)); }
public async Task <JsonResult> Delete(string id) { PageActionResult actionResult = new PageActionResult(); ApplicationRole role = await RoleManager.FindByIdAsync(id); if (role != null) { IdentityResult result = await RoleManager.DeleteAsync(role); if (result.Succeeded) { actionResult.Result = PageActionResultType.Success; actionResult.Message = "添加成功"; } else { actionResult.Result = PageActionResultType.Failed; actionResult.Message = "添加失败"; AddErrorsFromResult(result, actionResult); } } else { actionResult.Result = PageActionResultType.Failed; actionResult.Message = "添加失败,不存在"; } return(Json(actionResult)); }
public async Task <JsonResult> Create(ApplicationRole role) { PageActionResult actionResult = new PageActionResult(); if (ModelState.IsValid) { IdentityResult result = await RoleManager.CreateAsync(role); if (result.Succeeded) { actionResult.Result = PageActionResultType.Success; actionResult.Message = "添加成功"; } else { actionResult.Result = PageActionResultType.Failed; actionResult.Message = "添加失败"; AddErrorsFromResult(result, actionResult); } } else { actionResult.Result = PageActionResultType.Failed; actionResult.Message = "添加失败,参数错误"; } return(Json(actionResult)); }
private void AddErrorsFromResult(IdentityResult result, PageActionResult actionResult) { //foreach (string error in result.Errors) { // ModelState.AddModelError("", error); //} foreach (string error in result.Errors) { actionResult.Message += error + "|"; } }
/// <summary> /// 上传数据 /// </summary> /// <param name="fileBase64"></param> /// <param name="fileName"></param> /// <param name="articleId"></param> /// <returns></returns> public async Task <ActionResult> UploadFile(IList <IFormFile> files, int articleId = 0) { PageActionResult operateResult = new PageActionResult(); #region HttpClient调用 //HttpClient client = await CreateTokenRequestHttpClient(); //MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent();//创建多种类型的表单内容 //Dictionary<string, string> keyValues = new Dictionary<string, string>(); //keyValues["ArticleId"] = articleId.ToString(); //foreach (var keyValuePair in keyValues) //{ // StringContent formContent = new StringContent(keyValuePair.Value); // multipartFormDataContent.Add(formContent, keyValuePair.Key);//添加StringContent,表单Name属性一定要传且要和api接口参数一致,否则api端无法获取 //} //foreach (var formFile in files) //{ // if (formFile.Length > 0) // { // multipartFormDataContent.Add(new StreamContent(formFile.OpenReadStream()), "files", formFile.FileName);//添加StreamContent表单Name属性一定要传且要和api接口参数一致,否则api端无法获取 // } //} //var response = await client.PostAsync(Vars.FILESTORE_SITE + "/FileHandler/UploadArticelFile", multipartFormDataContent); //string msgBody = await response.Content.ReadAsStringAsync(); //try //{ // operateResult = JsonConvert.DeserializeObject<PageActionResult>(msgBody); //} //catch (Exception ex) { } #endregion RestApiClient restApiClient = new RestApiClient(Vars.FILESTORE_SITE); await restApiClient.AddAuthorization(Vars.IDENTITYSERVER_SITE + "/connect/token"); operateResult = restApiClient.PostFiles <PageActionResult>("/api/FileHandler/UploadArticelFile", new { ArticleId = articleId }, files); if (operateResult != null) { if (operateResult.Result == PageActionResultType.Failed) { return(Error(operateResult.Message)); } } else { return(Error("上传失败")); } return(Success(operateResult.Data)); }
public PageActionResult DeleteArticelFile([FromForm] string savePath) { PageActionResult operateResult = new PageActionResult(); try { string saveDirPath = Path.Combine(_hostingEnvironment.WebRootPath, "Upload", "File", "Article", savePath); if (Directory.Exists(saveDirPath)) { Directory.Delete(saveDirPath, true); } operateResult.Result = PageActionResultType.Success; operateResult.Message = "删除成功"; } catch (Exception ex) { LogHelper.WriteLog_LocalTxt(ex.ToJson()); operateResult.Result = PageActionResultType.Failed; operateResult.Message = "删除失败"; } return(operateResult); }
public async Task <PageActionResult> Move(PageMoveModel model) { PageActionResult result; if (string.IsNullOrEmpty(model.MovedNode) || string.IsNullOrEmpty(model.TargetNode) || (model.MovedNode == "-1") || (model.TargetNode == "-1") || (string.IsNullOrEmpty(model.Position))) { result = new PageActionResult(false, "bad request, failed to move page"); return(result); } var movedNode = await GetPage(model.MovedNode); var targetNode = await GetPage(model.TargetNode); if ((movedNode == null) || (targetNode == null)) { result = new PageActionResult(false, "bad request, page or target page not found"); return(result); } if (movedNode.Slug == _settings.DefaultPageSlug) { result = new PageActionResult(false, _sr["Moving the default/home page is not allowed"]); return(result); } switch (model.Position) { case "inside": // this case is when moving to a new parent node that doesn't have any children yet // target is the new parent // or when momving to the first position of the current parent movedNode.ParentId = targetNode.Id; movedNode.ParentSlug = targetNode.Slug; movedNode.PageOrder = 0; await _pageCommands.Update(movedNode.ProjectId, movedNode); await SortChildPages(targetNode.Id); break; case "before": // put this page before the target page beneath the same parent as the target if (targetNode.ParentId != movedNode.ParentId) { movedNode.ParentId = targetNode.ParentId; movedNode.ParentSlug = targetNode.ParentSlug; movedNode.PageOrder = targetNode.PageOrder - 1; await _pageCommands.Update(movedNode.ProjectId, movedNode); await SortChildPages(targetNode.ParentId); } else { //parent did not change just sort // set sort and re-sort movedNode.PageOrder = targetNode.PageOrder - 1; await _pageCommands.Update(movedNode.ProjectId, movedNode); await SortChildPages(targetNode.ParentId); } break; case "after": default: // put this page after the target page beneath the same parent as the target if (targetNode.ParentId != movedNode.ParentId) { movedNode.ParentId = targetNode.ParentId; movedNode.ParentSlug = targetNode.ParentSlug; movedNode.PageOrder = targetNode.PageOrder + 1; await _pageCommands.Update(movedNode.ProjectId, movedNode); await SortChildPages(targetNode.ParentId); } else { //parent did not change just sort movedNode.PageOrder = targetNode.PageOrder + 1; await _pageCommands.Update(movedNode.ProjectId, movedNode); await SortChildPages(targetNode.ParentId); } break; } //ClearNavigationCache(); result = new PageActionResult(true, "operation succeeded"); return(result); }
public PageActionResult UploadArticelFile([FromForm] UploadFileDto model) { PageActionResult operateResult = new PageActionResult(); List <UploadFileViewModel> filelist = new List <UploadFileViewModel>(); try { foreach (var formFile in model.Files) { if (formFile.Length > 0) { string time = DateTime.Now.ToString("yyyyMMddHHmmss"); string fileDir = Path.Combine("wwwroot", "Upload", "File", "Article", time); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } string filePath = Path.Combine(fileDir, formFile.FileName); string fileExt = Path.GetExtension(formFile.FileName); using (var stream = new FileStream(filePath, FileMode.Create)) { formFile.CopyTo(stream); } if (ImageHelper.IsWebImage(formFile.FileName)) { string thumbConfig = "340x200"; ImageFormat imgFormat; #region 图片格式 if (string.Compare(fileExt, ".jpg", true) == 0 || string.Compare(fileExt, ".jpeg", true) == 0) { imgFormat = ImageFormat.Jpeg; } else if (string.Compare(fileExt, ".gif", true) == 0) { imgFormat = ImageFormat.Gif; } else if (string.Compare(fileExt, ".bmp", true) == 0) { imgFormat = ImageFormat.Bmp; } else if (string.Compare(fileExt, ".ico", true) == 0) { imgFormat = ImageFormat.Icon; } else { imgFormat = ImageFormat.Png; } #endregion #region 生成缩略图 string[] thumbConfigSizes = thumbConfig.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string thumbConfigSize in thumbConfigSizes) { try { string[] thumbSizeInfo = thumbConfigSize.Split(new string[] { "x" }, StringSplitOptions.RemoveEmptyEntries); if (thumbSizeInfo.Length < 2) { continue; } int width = XConvert.ToInt32(thumbSizeInfo[0], 0); int height = XConvert.ToInt32(thumbSizeInfo[1], 0); if (width <= 0 || height <= 0) { continue; } else { string thumbSavePath = FileStoreUtil.GenerateThumbnailSavePath(filePath, width, height); ImageHelper.BuildThumbnail(filePath, thumbSavePath, imgFormat, width, height, true); } } catch (Exception ex) { LogHelper.WriteLog_LocalTxt(ex.ToJson()); } } #endregion } UploadFileViewModel file = new UploadFileViewModel { ArticleId = model.ArticleId, FileName = formFile.FileName, FileExt = fileExt, Path = Vars.FILESTORE_SITE + "/Upload/File/Article/" + time + @"/" + formFile.FileName, Thumb = Vars.FILESTORE_SITE + "/Upload/File/Article/" + time + @"/thumbs_" + Path.GetFileNameWithoutExtension(formFile.FileName) + @"/340_200" + fileExt, Directory = time//文件所在目录 }; filelist.Add(file); } } operateResult.Data = new { List = filelist }; operateResult.Result = PageActionResultType.Success; operateResult.Message = "上传成功"; } catch (Exception ex) { LogHelper.WriteLog_LocalTxt(ex.ToJson()); operateResult.Result = PageActionResultType.Failed; operateResult.Message = "上传失败"; } return(operateResult); }