Exemplo n.º 1
0
        private void ProcessAvatar(HttpContext context)
        {
            HttpPostedFile fileUpload = context.Request.Files["Filedata"];

            if (fileUpload != null && fileUpload.ContentLength > 0)
            {
                int    id   = CU.ToInt(context.Request.QueryString["i"]);
                string name = context.Request.QueryString["n"];

                UserEntity user = UserAccount.Current;
                if (user != null && user.id == id)
                {
                    if (name == null)
                    {
                        name = user.www;
                    }

                    string extension = Path.GetExtension(fileUpload.FileName).ToLower();
                    string fileName  = name + extension;

                    string originalPath = @"s\o\";
                    string datepath     = DateTime.Now.ToString("yyyyMM");
                    string ofileName    = rootPath + originalPath + datepath + "\\" + fileName;
                    if (SaveFile(fileUpload, ofileName))
                    {
                        string iconFileName = rootPath + originalPath + datepath + "\\" + name + ".png";
                        int    width, height;
                        if (IU.Resize(ofileName, iconFileName, 300, 300, out width, out height))
                        {
                            if (ofileName != iconFileName)
                            {
                                File.Delete(ofileName);
                            }
                        }
                        else /*TODO: log failed!*/ } {
                        FileController.CreateAttachment(new AttachmentEntity()
                        {
                            uid          = id,
                            url          = "/s/o/" + datepath + "/" + fileName,
                            physicalpath = iconFileName,
                            type         = 1
                        });

                        context.Response.StatusCode = 200;
                        string data = "{url:'" + "/s/o/" + datepath + "/" + name + ".png" + "',width:" + width + ",height:" + height + "}";
                        context.Response.Write(JU.BuildJSON(true, data));
                        return;
                }
            }
        }

        //内部服务器错误
        context.Response.StatusCode = 500;
        context.Response.Write(JU.Build(false, "图片上传失败"));
    }
Exemplo n.º 2
0
        public static void GetDistrict(HttpContext context)
        {
            string level = context.Request.QueryString["l"];
            string pid = context.Request.QueryString["p"];
            int    l, p;

            int.TryParse(level, out l);
            int.TryParse(pid, out p);

            IList <DistrictEntity> list = District.ListDistrict(l, p);

            if (list != null && list.Count > 0)
            {
                string json = JSON.Instance.ToJSON(list);
                context.Response.Write(JU.BuildJSON(true, json));
                return;
            }

            context.Response.Write(JU.AJAX_FAIL);
        }