예제 #1
0
        /// <summary>
        /// 更改头像
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> SavehobbyPhone(string id)
        {
            UploadPhone   updatePhone = new UploadPhone(_hostingEnv);
            BusinessImage image       = new BusinessImage();
            var           file        = Request.Form.Files.FirstOrDefault();
            var           hobby       = await _hobbyExtension.GetAll().Where(x => x.ID == Guid.Parse(id)).FirstOrDefaultAsync();

            //保存文件
            image.UploadPath = updatePhone.PhoneNewUpload(file, "User");

            image.UploaderID        = hobby.ID;
            image.RelevanceObjectID = hobby.ID;
            _businessImageExtension.AddAndSave(image);
            hobby.Avatar = image;
            _hobbyExtension.EditAndSave(hobby);
            return(Json(true));
        }
예제 #2
0
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> SavaUploaPhone(Guid id)
        {
            //TODO 获取对应的图片存储到服务器上和数据库上(业务ID ,当前用户ID ,图片路径)

            var file = Request.Form.Files.FirstOrDefault();

            if (file == null)
            {
                return(Json(new { isOk = false, message = "请选择上传的图片" }));
            }
            var user = User.Claims.FirstOrDefault();

            if (user == null)
            {
                //return Json(new { isOK = false, messsage = "请选择上传图片" });
                return(null);
            }
            //if (file == null)
            //{
            //    return null;
            //    //return Json(new { isOK = false, messsage = "请选择上传图片" });
            //}
            UploadPhone   updatePhone = new UploadPhone(_hostingEnv);
            BusinessImage image;

            image = new BusinessImage();
            var anAssociation = await _anAssociationExtension.GetAll().Include(x => x.User).Where(x => x.ID == id).FirstOrDefaultAsync();

            if (file.Length > 10485760)
            {
                return(null);
                //return Json(new { isOK = false, messsage = "图片大小有误,每张图片限制于10M" });
            }
            //保存文件
            image.UploadPath = updatePhone.PhoneNewUpload(file, "AnAssociation");

            image.UploaderID        = Guid.Parse(user.Value);
            image.RelevanceObjectID = anAssociation.ID;
            _businessImageRepository.AddAndSave(image);
            anAssociation.Avatar = image;
            _anAssociationExtension.EditAndSave(anAssociation);
            return(Json(true));
        }