//提交订单去结账 public JsonResult endAll() { var c_user = HttpContext.Cache["c_User"] as T_user; var uid = c_user.userId; GoShoesDBEntities db = new GoShoesDBEntities(); var ss = db.T_buyCar.Where(c => c.userId == uid).ToList(); foreach (var item in ss) { db.T_buyCar.Remove(item); } int rs = db.SaveChanges(); var obj = new { msg = "提交失败", code = 201 }; if (rs > 0) { obj = new { msg = "提交成功", code = 201 }; } return(Json(obj, JsonRequestBehavior.AllowGet)); }
//获取购物车数据 public JsonResult GetBuyCar() { GoShoesDBEntities db = new GoShoesDBEntities(); var ss = db.T_buyCar.ToList().Select(c => new { shoesId = c.shoesId, carNum = c.carNum, shoesImg = c.shoesImg, shoesPrices = c.shoesPrices, carSelfId = c.carSelfId }); List <carNode> all = new List <carNode>(); //取出所有购物车的鞋 foreach (var item in ss) { //获取鞋名 var name = db.T_shoes.Where(c => c.shoesId == item.shoesId).FirstOrDefault().shoesName; //获取鞋介绍 var js = db.T_shoes.Where(c => c.shoesId == item.shoesId).FirstOrDefault().shoesInfo; carNode one = new carNode(); one.count = item.carNum; one.img = item.shoesImg; one.jieshao = js; one.price = Convert.ToInt32(item.shoesPrices); one.sum = one.price * one.count; one.static1 = "可购买"; all.Add(one); } return(Json(all, JsonRequestBehavior.AllowGet)); }
public JsonResult loginIsOk(string name, string pwd) { GoShoesDBEntities db = new GoShoesDBEntities(); var s = db.T_user.Where(c => c.userName == name).FirstOrDefault(); var obj = new { msg = "登陆成功", code = 200, }; if (s == null) { obj = new { msg = "用户不存在", code = 201 }; return(Json(obj)); } if (s.userPassword != pwd) { obj = new { msg = "密码错误", code = 202 }; return(Json(obj)); } if (s.userClose == 1) { obj = new { msg = "用户被封禁", code = 203 }; return(Json(obj)); } if (s.userPowerId == 1) { obj = new { msg = "管理员登陆", code = 204 }; return(Json(obj)); } HttpContext.Cache["c_User"] = s; return(Json(obj)); }
//获取所有用户数据 public JsonResult GetList() { GoShoesDBEntities db = new GoShoesDBEntities(); var ss = db.T_user.ToList().Select(c => new { uid = c.userId, uname = c.userName, upwd = c.userPassword, uclose = c.userClose, upower = c.T_userType.userPowerName }); return(Json(ss, JsonRequestBehavior.AllowGet)); }
public JsonResult Ban(int uid) { GoShoesDBEntities db = new GoShoesDBEntities(); var s = db.T_user.Where(c => c.userId == uid).FirstOrDefault(); if (s.userClose == 1) { s.userClose = 0; var obj2 = new { msg = "解封失败", code = 203 }; int rs2 = db.SaveChanges(); if (rs2 > 0) { obj2 = new { msg = "解封成功", code = 204 }; } return(Json(obj2)); } s.userClose = 1; int rs = db.SaveChanges(); var obj = new { msg = "封禁失败", code = 201 }; if (rs > 0) { obj = new { msg = "封禁成功", code = 200 }; } return(Json(obj)); }
public JsonResult userRegister(string name, string pwd, string rePwd) { //var s = new //{ // userName = name, // userPassword = pwd, // userPowerId = 2, // userClose = 0 //}; var obj = new { msg = "注册失败", code = 201 }; if (string.IsNullOrEmpty(name)) { obj = new { msg = "用户名不能为空", code = 203 }; return(Json(obj)); } if (string.IsNullOrEmpty(pwd)) { obj = new { msg = "密码不能为空", code = 204 }; return(Json(obj)); } if (string.IsNullOrEmpty(rePwd)) { obj = new { msg = "再次输入密码不能为空", code = 205 }; return(Json(obj)); } if (pwd != rePwd) { obj = new { msg = "两次输入密码不一样", code = 206 }; return(Json(obj)); } GoShoesDBEntities db = new GoShoesDBEntities(); var abc = db.T_user.Where(c => c.userName == name).FirstOrDefault(); if (abc != null) { obj = new { msg = "注册失败,用户存在", code = 202 }; return(Json(obj)); } T_user s = new T_user(); s.userName = name; s.userPassword = pwd; s.userPowerId = 2; s.userClose = 0; db.T_user.Add(s); int rs = db.SaveChanges(); if (rs > 0) { obj = new { msg = "注册成功", code = 200 } } ; var ss = db.T_user.Where(c => c.userName == s.userName).FirstOrDefault(); HttpContext.Cache["c_User"] = s; return(Json(obj)); } }
public JsonResult CreateCar(string shoesName, int shoesPrice, string shoesImg, int shoesNum) { var obj = new { msg = "添加购物车失败", code = 201 }; var user = HttpContext.Cache["c_User"] as T_user; var uid = user.userId; GoShoesDBEntities db = new GoShoesDBEntities(); //用鞋名 查出鞋id var shoesId = db.T_shoes.Where(c => c.shoesName == shoesName).FirstOrDefault().shoesId; //看看购物车是否存在这鞋子 var s = db.T_buyCar.Where(c => c.shoesId == shoesId).FirstOrDefault(); if (s != null) { //如果有这个鞋子 那么久是加鞋数量 s.carNum += shoesNum; s.shoesPrices += shoesPrice; int rs = db.SaveChanges(); if (rs > 0) { obj = new { msg = "添加购物成功", code = 201 }; }//rs return(Json(obj)); } //如果没有这个鞋子 T_buyCar car = new T_buyCar(); car.carNum = shoesNum; car.shoesImg = shoesImg; car.shoesId = shoesId; car.shoesPrices = shoesPrice; car.userId = uid; db.T_buyCar.Add(car); int rs1 = db.SaveChanges(); if (rs1 > 0) { obj = new { msg = "添加购物车成功", code = 200 }; }//rs return(Json(obj)); }