public JsonResult SelectImgJson() { String id = Request["id"]; List <ImageModel> list = new List <ImageModel>(); if (!(id == null || id.Equals(""))) { list.Add(ImgService.selectImgById(Convert.ToInt64(id))); } else { DefaultConfig config = setConfig(); if (Request["limit"] != null) { config.limit = Convert.ToInt32(Request["limit"]); } if (config.order == StaticVal.Order.ORDER_BY_RANDOM) { list.AddRange(ImgService.random(config)); } else { list.Add(ImgService.selectImg(config)); } } DataTool.addHis("json", IPAddress(), list); return(Json(list, JsonRequestBehavior.AllowGet)); }
public void SelectImgPng( ) { DefaultConfig config = new DefaultConfig(); String id = Request["id"]; List <ImageModel> list = new List <ImageModel>(); if (!(id == null || id.Equals(""))) { list.Add(ImgService.selectImgById(Convert.ToInt64(id))); } else { config = setConfig(); if (config.order == StaticVal.Order.ORDER_BY_RANDOM) { list.AddRange(ImgService.random(config)); } else { list.Add(ImgService.selectImg(config)); } } DataTool.addHis("png", IPAddress(), list[0].Kid); string pathh = "C:\\Onedrive\\OneDrive - ITBYCX\\pmcdn\\" + Convert.ToInt32(list[0].Kid) / 1000 + "\\" + list[0].Kid + getExt(list[0].File_url); FileStream fs = new FileStream(pathh, FileMode.Open);//可以是其他重载方法 byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); if (getExt(list[0].File_url).Equals(".png")) { Response.ContentType = "image/png"; Response.BinaryWrite(byData); } else { Response.ContentType = "image/jpeg"; Response.BinaryWrite(byData); } }
public string favor() { string uname = Request.Cookies["user"].Value.ToString(); string kid = Request["kid"]; int status = UserService.updateFavor(uname, kid); ImageModel image = ImgService.selectImgById(Convert.ToInt64(kid)); JavaScriptSerializer javaScript = new JavaScriptSerializer(); if (status == 1) { return("1"); } else if (status == -1) { return("-1"); } else { return("0"); } }