public async Task <ActionResult <BaseResponse> > CopyTo(string GroupId, [FromBody] TypeCopyDto req) { //var GId = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value; var Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; //var Code = User.Claims.FirstOrDefault(a => a.Type == "Code").Value; //var isAdmin = User.Claims.FirstOrDefault(a => a.Type == "IsAdmin").Value.ToLower() == "true" ? true : false; //验证输入的groupid是否存在 var ex = await _gs.IsExist(a => a.Id == GroupId); if (!ex) { return(new BaseResponse { Success = false, Message = "输入的组织编号不存在" }); } //验证类型编号是否存在 var source = await _ts.CheckTypeAsync(a => a.Id == req.SourceId && a.GroupId == GroupId); if (source.IsExist == false) { return(new BaseResponse { Success = false, Message = "输入的源类型标示不存在" }); } if (source.Status == 0) { return(new BaseResponse { Success = false, Message = "源类型不能为目录节点" }); } var target = await _ts.CheckTypeAsync(a => a.Id == req.TargetId && a.GroupId == GroupId); if (target.IsExist == false) { return(new BaseResponse { Success = false, Message = "输入的目标类型标示不存在" }); } if (target.Status == 1) { return(new BaseResponse { Success = false, Message = "目标类型不能为叶子节点" }); } ////验证用户权限 //if (!(isAdmin && (GId == GroupId || Code == _config["Group"]))) //{ // return Unauthorized("没有权限"); //} var rm = await _ts.CopyTypeAsync(Account, req.SourceId, req.TargetId); return(rm); }
public async Task <ActionResult <BaseResponse> > CopyFilesAsync(string GroupId, [FromBody] TypeCopyDto req) { var GId = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value; var Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; var Code = User.Claims.FirstOrDefault(a => a.Type == "Code").Value; var isAdmin = User.Claims.FirstOrDefault(a => a.Type == "IsAdmin").Value.ToLower() == "true" ? true : false; //验证输入的groupid是否存在 var ex = await _gs.IsExist(a => a.Id == GroupId); if (!ex) { return(new BaseResponse { Success = false, Message = "输入的组织编号不存在" }); } //验证类型编号是否存在 var source = await _ts.CheckTypeAsync(a => a.Id == req.SourceId && a.GroupId == GroupId); if (source.IsExist == false) { return(new BaseResponse { Success = false, Message = "输入的源类型标示不存在" }); } if (source.Status == 0) { return(new BaseResponse { Success = false, Message = "源类型不能为目录节点" }); } var target = await _ts.CheckTypeAsync(a => a.Id == req.TargetId && a.GroupId == GroupId); if (target.IsExist == false) { return(new BaseResponse { Success = false, Message = "输入的目标类型标示不存在" }); } if (target.Status == 0) { return(new BaseResponse { Success = false, Message = "目标类型不能为目录节点" }); } //类型文件保存的相对路径:Files+组织编号+TypeFiles+TypeId+文件名称 string webRootPath = _webHostEnvironment.WebRootPath; //wwwroot文件夹 string userPath = Path.Combine(GroupId, "TypeFiles", req.TargetId.ToString()); //用户头像保存位置 userPath = Path.Combine(_config["StoredFilesPath"], userPath); var filePath = Path.Combine(webRootPath, userPath);//物理路径 //如果路径不存在,创建路径 if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } //类型图片保存的相对路径:Files+组织编号+TypeImage+TypeId+文件名称 string ImagePath = Path.Combine(GroupId, "TypeImage", req.TargetId.ToString());//用户头像保存位置 ImagePath = Path.Combine(_config["StoredImagesPath"], ImagePath); ImagePath = Path.Combine(webRootPath, ImagePath); //物理路径,不包含头像名称 //如果路径不存在,创建路径 if (!Directory.Exists(ImagePath)) { Directory.CreateDirectory(ImagePath); } //注意此处的路径,在windows下为\\,linux下为/ int fi = filePath.LastIndexOf('/'); int im = ImagePath.LastIndexOf('/'); filePath = filePath.Substring(0, fi); ImagePath = ImagePath.Substring(0, im); var rm = await _ts.CopyTypeFilesAsync(Account, filePath, ImagePath, req.SourceId, req.TargetId); return(rm); }