//连接redis服务器
public static RedisClient client = new RedisClient("192.168.43.30", 6379);
public static List<BasketBook> basketBookList = new List<BasketBook>();
public static string path = "http://localhost:30889/";
#region 首页
public ActionResult Index(string ticket,int ? cid,string str="", int pageIndex = 1, int pageSize = 6)
{
ViewBag.ticket = ticket;
Uri uri = new Uri(path);
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = uri;
HttpContent context = new StringContent(ticket);
context.Headers.Add("Authorization", "BasicAuth"+ticket);
var pashAction = httpClient.GetAsync("api/BookPage/cid=" + cid+"&str="+str);
var pashResult = pashAction.Result;
if (pashResult.StatusCode == System.Net.HttpStatusCode.OK)
{
var result = pashResult.Content.ReadAsStringAsync().Result;
var list = JsonConvert.DeserializeObject<List<Book>>(result);
int totalCount = list.Count();
int totallPage = (int)Math.Ceiling(totalCount / (double)pageSize);
PageList<Book> blist = new PageList<Book>(list, pageIndex, pageSize, ref totallPage, ref totalCount);
httpClient.Dispose();
return View(blist);
}else
{
return Content("<script>alert('获取资源错误,错误代码为:"+pashResult.StatusCode+"')</script>");
}
}
#endregion