예제 #1
0
        /// <summary>
        /// 用户头像上传
        /// </summary>
        /// <param name="file"></param>
        /// <param name="uploaPath"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static KingResponse UploadAvatarFile(HttpPostedFile file, string uploaPath, string id)
        {
            KingResponse response;

            if (!Directory.Exists(uploaPath))
            {
                Directory.CreateDirectory(uploaPath);
            }
            string Extension = Path.GetExtension(file.FileName);

            //////////////重新命名文件名///////////////
            uploaPath = uploaPath + "\\" + id + Extension;
            try
            {
                if (File.Exists(uploaPath))
                {
                    File.Delete(uploaPath);
                }
                file.SaveAs(uploaPath);
            }
            catch (Exception ex)
            {
                //response = KingResponse.GetErrorResponse("保存文件失败:" + ex.Message);
                //return response;
            }
            Extension = Extension.Remove(Extension.IndexOf('.'), 1);
            response  = KingResponse.GetResponse(null, new
            {
                ID       = id,
                FileName = file.FileName.Substring(0, file.FileName.IndexOf('.')),
                //FilePath = string.Format("{0}/{1}/{2}.{3}", GetFileServerHttp(), "KingsunFiles/AvatarFile", id, Extension)
                FilePath = string.Format("{0}/{1}/{2}{3}", System.Configuration.ConfigurationManager.AppSettings["FileAddress"].ToString(), "KingsunFiles/AvatarFile", id, Extension)
            });
            return(response);
        }
예제 #2
0
        public KingResponse Post()
        {
            string       PrePath = System.Configuration.ConfigurationManager.AppSettings["FileAddress"] + "/KingsunFiles/";
            KingResponse response;

            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                HttpPostedFile     file  = files[files.AllKeys[0]];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    response = Bll.FileUploadBll.UploadFile(file, PrePath);
                }
                else
                {
                    response = KingResponse.GetErrorResponse("没有选择文件!");
                }
            }
            catch
            {
                response = KingResponse.GetErrorResponse("处理过程中出现错误!");
                return(response);
            }
            return(response);
        }
예제 #3
0
        public KingResponse Post(string JsonFile)
        {
            rFileResource fResource = JsonHelper.DecodeJson <rFileResource>(JsonFile);
            string        PrePath   = System.Configuration.ConfigurationManager.AppSettings["FileAddress"] + "/KingsunFiles/SmartClassFile/" + fResource.UserName;
            KingResponse  response;

            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                HttpPostedFile     file  = files[files.AllKeys[0]];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    response = Bll.FileUploadBll.UploadSmartClassFile(file, PrePath, fResource);
                }
                else
                {
                    response = KingResponse.GetErrorResponse("文件不存在!");
                }
            }
            catch
            {
                response = KingResponse.GetErrorResponse("处理过程中出现错误!");
                return(response);
            }
            return(response);
        }
예제 #4
0
        public JsonResult GetCourseAppList(int CourseID)
        {
            ApplyPartModel appList  = appbll.GetCourseAppList(CourseID);
            KingResponse   response = KingResponse.GetResponse(null, appList);

            return(Json(response));
        }
예제 #5
0
        public JsonResult GetBookListByEditionID(int ediID, int subjectId, int stageId)
        {
            List <CourseModel> appModel = appbll.GetBookListByEditionID(ediID, subjectId, stageId);
            KingResponse       response = KingResponse.GetResponse(null, appModel);

            return(Json(response));
        }
예제 #6
0
        // POST api/<controller>
        public KingResponse Post(string id)
        {
            //string PrePath = System.Web.Hosting.HostingEnvironment.MapPath("~/KingsunFiles/AvatarFile");
            string       PrePath = System.Configuration.ConfigurationManager.AppSettings["FileAddress"] + "/KingsunFiles/AvatarFile";
            KingResponse response;

            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                HttpPostedFile     file  = files[files.AllKeys[0]];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    response = Bll.FileUploadBll.UploadAvatarFile(file, PrePath, id);
                }
                else
                {
                    response = KingResponse.GetErrorResponse("文件不存在!");
                }
            }
            catch
            {
                response = KingResponse.GetErrorResponse("处理过程中出现错误!");
                return(response);
            }
            return(response);
        }
예제 #7
0
        /// <summary>
        /// 通过学段获取学科
        /// </summary>
        /// <param name="stageID"></param>
        /// <returns></returns>
        public JsonResult GetSubjectListByStageID(int stageID)
        {
            CookieHelper.SetCookie("StageID", stageID.ToString());
            List <SubjectModel> subModel = indexbll.GetSubjectByStage(stageID);
            KingResponse        response = KingResponse.GetResponse(null, subModel);

            return(Json(response));
        }
예제 #8
0
        /// <summary>
        /// 切换学段获取教材
        /// </summary>
        /// <param name="subjectId"></param>
        /// <param name="stageId"></param>
        /// <returns></returns>
        public JsonResult GetBookListAndMovice(int subjectId, int stageId)
        {
            CookieHelper.SetCookie("StageID", stageId.ToString());
            ApplyModel   appModel = appbll.GetCourseAndMovice(subjectId.ToString(), stageId);
            KingResponse response = KingResponse.GetResponse(null, appModel);

            return(Json(response));
        }
예제 #9
0
        public JsonResult GetMicroCourseByKey(string key = "")
        {
            MicroCourseBLL mCourseBll    = new MicroCourseBLL();
            MicroResource  microresource = mCourseBll.GetMicroCourseByKey(key);
            KingResponse   response      = KingResponse.GetResponse(null, microresource);

            return(Json(response));
        }
예제 #10
0
        public static KingResponse GetResponse(KingRequest request, object data)
        {
            KingResponse response = new KingResponse();

            response.Success  = true;
            response.ErrorMsg = "";
            if (request != null)
            {
                response.RequestID = request.ID;
            }
            else
            {
                response.RequestID = "";
            }
            response.Data = data;
            return(response);
        }
예제 #11
0
        /// <summary>
        /// 按错误数据创建输出对象
        /// </summary>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public static KingResponse GetErrorResponse(string errorMsg, KingRequest request = null)
        {
            KingResponse response = new KingResponse();

            response.Success  = false;
            response.ErrorMsg = errorMsg;
            if (request != null)
            {
                response.RequestID = request.ID;
            }
            else
            {
                response.RequestID = "";
            }
            response.Data = null;
            return(response);
        }
예제 #12
0
        public string Post(string id)
        {
            //WebClient client = new WebClient();
            //string SchoolUrl = System.Configuration.ConfigurationManager.AppSettings["SchoolUrl"].ToString();
            //byte[] bt = client.UploadFile(SchoolUrl + "api/UploadAvatar/" + avatar.UserID, null, avatar.FilePath);
            //string temp = System.Text.Encoding.UTF8.GetString(bt);
            //List<string> ls = temp.Split(',').ToList();
            //List<string> ls1 = ls[4].Split('\"').ToList();
            //return ls1[3];
            //UploadAvatar

            string       PrePath = System.Web.Hosting.HostingEnvironment.MapPath("~/KingsunFiles/AvatarFile");
            KingResponse response;
            string       Extension = "";

            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                HttpPostedFile     file  = files[files.AllKeys[0]];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    if (!Directory.Exists(PrePath))
                    {
                        Directory.CreateDirectory(PrePath);
                    }
                    Extension = Path.GetExtension(file.FileName);
                    //////////////重新命名文件名///////////////
                    PrePath = PrePath + "\\" + id + Extension;
                    try
                    {
                        if (File.Exists(PrePath))
                        {
                            File.Delete(PrePath);
                        }
                        file.SaveAs(PrePath);
                    }
                    catch (Exception ex)
                    {
                        response = KingResponse.GetErrorResponse("保存文件失败:" + ex.Message);
                        //return response;
                    }
                    //response = UploadAvatarFile(file, PrePath, id);
                }
                else
                {
                    response = KingResponse.GetErrorResponse("文件不存在!");
                }
            }
            catch
            {
                response = KingResponse.GetErrorResponse("处理过程中出现错误!");
                //return response;
            }
            string FilePath = string.Format("{0}/{1}/{2}{3}", System.Configuration.ConfigurationManager.AppSettings["FileAddress"].ToString(), "KingsunFiles/AvatarFile", id, Extension);
            //JavaScriptSerializer serializer = new JavaScriptSerializer();
            //string str = serializer.Serialize(FilePath);
            //HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
            //return result;
            string strGUID = System.Guid.NewGuid().ToString();

            return(FilePath + "?ranM=" + strGUID);
            //return response;
        }