예제 #1
0
        /// <summary>
        /// 将图片的URL或者Base64字符串转为图片并上传到服务器,返回上传后的完整图片URL
        /// </summary>
        /// <param name="imgBase64OrUrl">URL地址或者Base64字符串</param>
        /// <returns></returns>
        public static string GetImgUrl(string imgBase64OrUrl)
        {
            if (imgBase64OrUrl.Contains("data:image"))
            {
                Image  img      = ImgHelper.GetImgFromBase64Url(imgBase64OrUrl);
                string fileName = $"{IdHelper.GetId()}.jpg";

                string dir = Path.Combine(HttpContext.Current.Server.MapPath("~/"), "Upload", "Img");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                img.Save(Path.Combine(dir, fileName));

                return($"{GlobalSwitch.WebRootUrl}/Upload/Img/{fileName}");
            }
            else
            {
                return(imgBase64OrUrl);
            }
        }
예제 #2
0
        public static void InitEntity(this object entity)
        {
            var op = AutofacHelper.GetScopeService <IOperator>();

            if (entity.ContainsProperty("Id"))
            {
                entity.SetPropertyValue("Id", IdHelper.GetId());
            }
            if (entity.ContainsProperty("CreateTime"))
            {
                entity.SetPropertyValue("CreateTime", DateTime.Now);
            }
            if (entity.ContainsProperty("CreatorId"))
            {
                entity.SetPropertyValue("CreatorId", op?.UserId);
            }
            if (entity.ContainsProperty("CreatorRealName"))
            {
                entity.SetPropertyValue("CreatorRealName", op?.Property?.RealName);
            }
        }