/// <summary> /// 设置更新组织机构logo /// </summary> /// <param name="id">组织机构主键id</param> /// <param name="imageFile">准备要更新的组织机构logo文件信息</param> /// <returns></returns> public async Task <OperationResult> SetOrganizeLogo(Guid id, Task <FileInfo> imageFile) { if (!OrganizeRepository.CheckExists(m => m.Id == id)) { throw new Exception("id:组织机构信息不存在"); } else { var file = await imageFile; using (Bitmap bitmap = new Bitmap(file.FullName)) { byte[] imageBits = bitmap.ToBytes(); var result = OrganizeRepository.TrackEntities.First(m => m.Id == id); result.OrganizeLogo = imageBits; result.OrganizeLogoPath = Path.Combine("~/OrganizeLogos", file.Name); if (OrganizeRepository.Update(result) > 0) { return(new OperationResult(OperationResultType.Success, "操作成功")); } else { throw new Exception("id:操作失败"); } } } }
/// <summary> /// 获取组织机构logo /// </summary> /// <param name="id">组织机构主键id</param> /// <returns></returns> public byte[] GetOrganizeLogo(Guid id) { if (!OrganizeRepository.CheckExists(m => m.Id == id)) { throw new Exception("id:查询信息不存在"); } else { var result = OrganizeRepository.TrackEntities.First(m => m.Id == id); if (string.IsNullOrEmpty(result.OrganizeLogoPath) && (result.OrganizeLogo?.Length <= 0 || result.OrganizeLogo == null)) { return(Properties.Resources.OrganizeLog.ToBytes()); } else { var imgPath = HttpContext.Current.Server.MapPath($"{result.OrganizeLogoPath}"); if (File.Exists(imgPath)) { return(File.ReadAllBytes(imgPath)); } else { imgPath = HttpContext.Current.Server.MapPath($"~/OrganizeLogos\\{result.Id.ToString()}"); string str = result.OrganizeLogo.CreateImageFromBytes(imgPath); result.OrganizeLogoPath = $"~/OrganizeLogos\\{str.Substring(str.LastIndexOf('\\') + 1)}"; OrganizeRepository.Update(result); return(result.OrganizeLogo); } } } }