/// <summary> /// 修改管理员账号 /// </summary> /// <param name="context"></param> public void UpdateUsersRequest(HttpContext context) { var response = new ResponseMessage(); try { string userName = context.Request.Form["UserName"]; string role = context.Request.Form["Role"]; string id = context.Request.Form["SuId"]; var adminUser = new AdminUser(); adminUser.SuId = id; adminUser.Role = Convert.ToInt32(role); adminUser.UserName = userName; adminUser.Pwd = "123456"; var edi = _AdminUserService.Update(adminUser); if (edi) { response.code = 0; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "操作失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddUsersRequest(HttpContext context) { var response = new ResponseMessage(); try { string userName = context.Request.Form["name"]; string userPwd = context.Request.Form["pwd"]; string userEmail = context.Request.Form["email"]; string usernick = context.Request.Form["nick"]; Users userInfo = new Users(); userInfo.UserId = Guid.NewGuid().ToString(); userInfo.UserName = userName; userInfo.Pwd = userPwd; userInfo.Email = userEmail; userInfo.Nick = usernick; userInfo.DeliveryId = "?"; var add = _userInfoService.AddUserInfo(userInfo); response.code = add == true ? 0 : 500; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> ///删除 /// </summary> /// <param name="context"></param> public void DeleteNewsRequest(HttpContext context) { var response = new ResponseMessage(); try { var id = context.Request["id"]; var del = _InfoService.Delete(id); if (del) { response.code = 0; response.msg = "删除成功"; context.Response.Write(SerializeHelp.ToJson(response)); } response.code = 500; response.msg = "删除失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "删除失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 修改 /// </summary> /// <param name="context"></param> public void UpdateNewsRequest(HttpContext context) { var response = new ResponseMessage(); try { string id = context.Request.Form["NewsId"]; string title = context.Request.Form["Title"]; string nTypes = context.Request.Form["NTypes"]; string content = context.Request.Form["Content"]; var pushTime = Convert.ToDateTime(context.Request.Form["PushTime"]); var path = context.Request.Form["PhotoId"]; var states = Convert.ToInt32(context.Request.Form["States"]); News News = new News() { NewsId = id, Title = title, NTypes = nTypes, Content = content, PhotoUrl = path, States = states, PushTime = pushTime }; var edi = _InfoService.Update(News); response.code = edi == true ? 0 : 500; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddUsersRequest(HttpContext context) { var response = new ResponseMessage(); try { string userName = context.Request.Form["UserName"]; string role = context.Request.Form["Role"]; var adminUser = new AdminUser(); adminUser.SuId = Guid.NewGuid().ToString(); adminUser.Role = 2;//新开账户不给予赋予权限 adminUser.UserName = userName; adminUser.Pwd = "123456"; var add = _AdminUserService.Add(adminUser); if (add) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "操作失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 修改用户 /// </summary> /// <param name="context"></param> public void UpdateCustomerRequest(HttpContext context) { var response = new ResponseMessage(); try { string userName = context.Request.Form["UserName"]; string userPwd = context.Request.Form["Pwd"]; string userEmail = context.Request.Form["Email"]; string usernick = context.Request.Form["Nick"]; string id = context.Request.Form["UserId"]; string deliveryId = context.Request.Form["DeliveryId"]; Customer userInfo = new Customer(); userInfo.UserName = userName; userInfo.Pwd = userPwd; userInfo.Email = userEmail; userInfo.Nick = usernick; userInfo.DeliveryId = deliveryId; userInfo.UserId = id; var edi = _userInfoService.UpdateUserInfo(userInfo); response.code = edi == true ? 0 : 500; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 获取商品 /// </summary> /// <returns></returns> public string GetProductList() { try { var list1 = _InfoProductService.GetList().AsQueryable(); var list2 = _InfoImageService.GetList().AsQueryable(); var list3 = from c in list1 select new ProductEx { Content = c.Content, CateId = c.CateId, MarketPrice = c.MarketPrice, Path = list2.Where(u => u.ProductId == c.ProductId).FirstOrDefault().PhotoUrl, Price = c.Price, ProductId = c.ProductId, Title = c.Title, Stock = c.Stock }; return(SerializeHelp.ToJson(list3.ToList())); } catch (Exception e) { _log.Error(e.Message); return(""); } }
/// <summary> /// 修改 /// </summary> /// <param name="context"></param> public void UpdateCategoryRequest(HttpContext context) { var response = new ResponseMessage(); try { string id = context.Request.Form["id"]; string name = context.Request.Form["CateName"]; var model = _infoService.GetList().Where(y => y.CateId == id).SingleOrDefault(); Category category = new Category(); category.CateId = id; category.CateName = name; category.ParentId = model.ParentId; var edi = _infoService.Update(category); if (edi) { response.code = 0; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); } response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { string error = e.Message; response.code = 500; response.msg = "请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 编辑订单状态 /// </summary> /// <param name="context"></param> public void EditOrderStatusRequest(HttpContext context) { var response = new ResponseMessage(); var id = context.Request.Form["id"]; var list = _infoService.GetList().Where(y => y.OrdersId == id).SingleOrDefault(); if (list == null) { response.code = 101; response.msg = "发货失败,不存在该订单信息"; context.Response.Write(SerializeHelp.ToJson(response)); return; } list.States = 2; //考虑商品库存 ? var update = _infoService.Update(list); if (update) { response.code = 0; response.msg = "发货成功"; context.Response.Write(SerializeHelp.ToJson(response)); } response.code = 500; response.msg = "发货失败"; context.Response.Write(SerializeHelp.ToJson(response)); }
/// <summary> /// 判断该用户是否存在 /// </summary> /// <param name="context"></param> public void AdminUserIsExistRequest(HttpContext context) { var response = new ResponseMessage <string>(); try { string userName = context.Request.Form["UserName"]; string userPwd = context.Request.Form["Pwd"]; var list = _userInfoService.GetList().Where(y => y.UserName == userName && y.Pwd == userPwd); if (list != null) { response.code = 0; response.msg = "登陆成功"; response.model = list.FirstOrDefault().Role.ToString(); context.Response.Write(SerializeHelp.ToJson(response)); } else { response.code = 500; response.msg = "用户名或者密码错误"; context.Response.Write(SerializeHelp.ToJson(response)); } } catch (Exception e) { _log.Error("判断该用户是否存在报错 56:" + e.Message); response.code = 500; response.msg = "请求错误,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddProductRequest(HttpContext context) { var response = new ResponseMessage(); try { string title = context.Request.Form["Title"]; string cateId = context.Request.Form["CateId"]; string content = context.Request.Form["Content"]; var marketPrice = Convert.ToDecimal(context.Request.Form["MarketPrice"]); var price = Convert.ToDecimal(context.Request.Form["Price"]); var stock = Convert.ToInt32(context.Request.Form["Stock"]); var postTime = Convert.ToDateTime(context.Request.Form["PostTime"]); var path = context.Request.Form["PhotoId"]; var Id = Guid.NewGuid().ToString(); /*如何开启事务 ?*/ //图片 Photo photo = new Photo { PhotoId = Guid.NewGuid().ToString(), PhotoUrl = path, ProductId = Id }; _photoInfoService.Add(photo); //商品 Product Product = new Product() { ProductId = Id, Title = title, CateId = cateId, Content = content, MarketPrice = marketPrice, Stock = stock, PostTime = postTime, Price = price, Icon = path }; var add = _InfoService.Add(Product); response.code = add == true ? 0 : 500; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { string eroor = e.Message; response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
public void UploadImg(HttpContext context) { if (context.Request.Files.Count > 0) { var imgSrc = SerializeHelp.UploadFile(context); var res = new { msg = "ok", code = 0, src = imgSrc }; context.Response.Write(SerializeHelp.ToJson(res)); } else { var res = new { msg = "no", code = 500, src = "" }; context.Response.Write(res); } }
///// <summary> /////删除用户 ///// </summary> ///// <param name="context"></param> //public void DeleteOrderRequest(HttpContext context) //{ // var response = new ResponseMessage(); // try // { // var id = context.Request["id"]; // var del = _infoService.Delete(id); // if (del) // { // response.code = 0; // response.msg = "删除成功"; // context.Response.Write(SerializeHelp.ToJson(response)); // } // response.code = 500; // response.msg = "删除失败"; // context.Response.Write(SerializeHelp.ToJson(response)); // } // catch (Exception e) // { // response.code = 500; // response.msg = "操作失败,请重试"; // context.Response.Write(SerializeHelp.ToJson(response)); // } //} /// <summary> /// 前端用户确认结算修改用户 /// </summary> /// <param name="context"></param> public void UpdateOrderRequest(HttpContext context) { var response = new ResponseMessage(); try { //订单动作 string action = context.Request.Form["action"]; string ordersId = context.Request.Form["OrdersId"]; var order = _infoService.GetList().Where(y => y.OrdersId == ordersId).FirstOrDefault(); if (action == "1") { string deliveryId = context.Request.Form["DeliveryId"]; string remark = context.Request.Form["Remark"]; //订单 order.Remark = remark; order.OrdersId = ordersId; order.Orderdate = DateTime.Now; order.States = 1; order.DeliveryId = deliveryId; } else if (action == "3") { order.States = 3; } else if (action == "4") { order.States = 4; } var add1 = _infoService.Update(order); if (add1) { response.code = 0; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 0; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); return; } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 修改用户 /// </summary> /// <param name="context"></param> public void UpdateProductRequest(HttpContext context) { var response = new ResponseMessage(); try { string id = context.Request.Form["ProductId"]; string title = context.Request.Form["Title"]; string cateId = context.Request.Form["CateId"]; string type = context.Request.Form["Content"]; string content = context.Request.Form["Content"]; var marketPrice = Convert.ToDecimal(context.Request.Form["MarketPrice"]); var price = Convert.ToDecimal(context.Request.Form["Price"]); var stock = Convert.ToInt32(context.Request.Form["Stock"]); var postTime = Convert.ToDateTime(context.Request.Form["PostTime"]); Product Product = new Product() { ProductId = id, Title = title, CateId = cateId, Content = content, MarketPrice = marketPrice, Stock = stock, PostTime = postTime, Price = price }; var edi = _InfoService.Update(Product); if (edi) { response.code = edi == true ? 0 : 500; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); } else { response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } } catch (Exception e) { response.code = 500; response.msg = "请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加 /// </summary> /// <param name="context"></param> public void AddFavoriteRequest(HttpContext context) { var response = new ResponseMessage(); try { //string id = context.Request.Form["FavoriteId"]; string productId = context.Request.Form["ProductId"]; string userId = context.Request.Form["UserId"]; var exist = _InfoService.GetList().Where(y => y.ProductId == productId && y.UserId == userId).ToList(); if (exist.Count() > 0) { response.code = 500; response.msg = "已收藏该商品,请勿重复添加"; context.Response.Write(SerializeHelp.ToJson(response)); return; } Favorite Favorite = new Favorite() { FavoriteId = Guid.NewGuid().ToString(), ProductId = productId, UserId = userId, DateTime = DateTime.Now, }; var add = _InfoService.Add(Favorite); if (add) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { string error = e.Message; response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
///// <summary> ///// 批量删除 ///// </summary> ///// <param name="context"></param> //public void DeleteListAppraiseRequest(HttpContext context) //{ // // ? //} ///// <summary> ///// 搜索用户 ///// </summary> ///// <param name="context"></param> //public void SeachAppraiseRequest(HttpContext context) //{ // var username = context.Request["name"]; // var list = _userInfoService.GetList().Where(y => y.UserName.Contains(username)).ToList(); // var res = SerializeHelp.ToTableJson<Appraise>(list); // context.Response.Write(res); //} /// <summary> ///删除用户 /// </summary> /// <param name="context"></param> public void DeleteAppraiseRequest(HttpContext context) { var response = new ResponseMessage(); try { var id = context.Request["id"]; var del = _userInfoService.Delete(id); response.code = del == true ? 0 : 500; response.msg = "删除成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "删除失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddCategoryRequest(HttpContext context) { var response = new ResponseMessage(); try { string name = context.Request.Form["cateName"]; string parentId = context.Request.Form["parentId"]; string type = context.Request.Form["type"]; Category category = new Category(); if (type == "1") //顶级 { category.ParentId = "0"; } else { category.ParentId = parentId; } category.CateId = Guid.NewGuid().ToString(); category.CateName = name; var add = _infoService.Add(category); if (add) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); } else { response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } } catch (Exception e) { response.code = 500; response.msg = "请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加 /// </summary> /// <param name="context"></param> public void AddNewsRequest(HttpContext context) { var response = new ResponseMessage(); try { string id = context.Request.Form["NewsId"]; string title = context.Request.Form["Title"]; string nTypes = context.Request.Form["NTypes"]; string content = context.Request.Form["Content"]; // var pushTime = Convert.ToDateTime(context.Request.Form["PushTime"]); var states = Convert.ToInt32(context.Request.Form["States"]); var path = context.Request.Form["PhotoUrl"]; News News = new News() { NewsId = Guid.NewGuid().ToString(), Title = title, NTypes = nTypes, Content = content, PhotoUrl = path, States = states, PushTime = DateTime.Now }; _log.Error($"咨询添加请求体:{SerializeHelp.ToJson(News)}"); var add = _InfoService.Add(News); response.code = add == true ? 0 : 500; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { string error = e.Message; _log.Error($"咨询添加失败:{error}"); response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加 /// </summary> /// <param name="context"></param> public void AddAppraiseRequest(HttpContext context) { var response = new ResponseMessage <string>(); try { string grade = context.Request.Form["Grade"]; string userId = context.Request.Form["UserId"]; string productId = context.Request.Form["ProductId"]; string content = context.Request.Form["Content"]; Appraise appraise = new Appraise { AppraiseId = Guid.NewGuid().ToString(), Grade = Convert.ToInt32(grade), ProductId = productId, RateTime = DateTime.Now, UserId = userId, Content = content }; var add = _userInfoService.Add(appraise); if (add) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加 /// </summary> /// <param name="context"></param> public void AddDeliveryRequest(HttpContext context) { var response = new ResponseMessage<string>(); try { string complete = context.Request.Form["Complete"]; string userId = context.Request.Form["UserId"]; string consignee = context.Request.Form["Consignee"]; string phone = context.Request.Form["Phone"]; Delivery Delivery = new Delivery { DeliveryId = Guid.NewGuid().ToString(), Complete = complete, Consignee = consignee, Phone = phone, UserId = userId, }; var add = _userInfoService.Add(Delivery); if (add) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 修改用户 /// </summary> /// <param name="context"></param> public void UpdateDeliveryRequest(HttpContext context) { var response = new ResponseMessage(); try { string complete = context.Request.Form["Complete"]; string userId = context.Request.Form["UserId"]; string consignee = context.Request.Form["Consignee"]; string phone = context.Request.Form["Phone"]; string deliveryId = context.Request.Form["DeliveryId"]; Delivery Delivery = new Delivery { DeliveryId = deliveryId, Complete = complete, Consignee = consignee, Phone = phone, UserId = userId, }; var edi = _userInfoService.Update(Delivery); if (edi) { response.code = 0; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddCustomerRequest(HttpContext context) { var response = new ResponseMessage <string>(); try { string userName = context.Request.Form["name"]; string userPwd = context.Request.Form["pwd"]; string userEmail = context.Request.Form["email"]; string usernick = context.Request.Form["nick"]; Customer userInfo = new Customer(); userInfo.UserId = Guid.NewGuid().ToString(); userInfo.UserName = userName; userInfo.Pwd = userPwd; userInfo.Email = userEmail; userInfo.Nick = usernick; userInfo.DeliveryId = "?"; var add = _userInfoService.AddUserInfo(userInfo); if (add) { response.code = 0; response.msg = "添加成功"; //response.model = userInfo.UserId + '.' + userInfo.Nick; response.model = userInfo.UserId; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 修改用户 /// </summary> /// <param name="context"></param> public void UpdateAppraiseRequest(HttpContext context) { var response = new ResponseMessage(); try { string grade = context.Request.Form["Grade"]; string userId = context.Request.Form["UserId"]; string productId = context.Request.Form["ProductId"]; string appraiseId = context.Request.Form["AppraiseId"]; Appraise appraise = new Appraise { AppraiseId = appraiseId, Grade = Convert.ToInt32(grade), ProductId = productId, RateTime = DateTime.Now, UserId = userId, }; var edi = _userInfoService.Update(appraise); if (edi) { response.code = 0; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddAdminUserRequest(HttpContext context) { var response = new ResponseMessage(); try { string userName = context.Request.Form["UserName"]; //string userPwd = context.Request.Form["Pwd"]; string userEmail = context.Request.Form["Role"]; string suId = context.Request.Form["SuId"]; AdminUser userInfo = new AdminUser(); userInfo.UserName = userName; userInfo.Pwd = "123456"; //管理员默认密码 userInfo.Role = Convert.ToInt32(userEmail); userInfo.SuId = suId; var add = _userInfoService.Add(userInfo); if (add) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "操作失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 修改用户 /// </summary> /// <param name="context"></param> public void UpdateAdminUserRequest(HttpContext context) { var response = new ResponseMessage(); try { string userName = context.Request.Form["UserName"]; string userPwd = context.Request.Form["Pwd"]; string userEmail = context.Request.Form["Role"]; string suId = context.Request.Form["SuId"]; AdminUser userInfo = new AdminUser(); userInfo.UserName = userName; userInfo.Pwd = userPwd; userInfo.Role = Convert.ToInt32(userEmail); userInfo.SuId = suId; var edi = _userInfoService.Update(userInfo); if (edi) { response.code = 0; response.msg = "修改成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 500; response.msg = "修改失败"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { response.code = 500; response.msg = "操作失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }
/// <summary> /// 组织树状结构 /// </summary> /// <param name="context"></param> public void CreateTreeRequest(HttpContext context) { var list = _infoService.CreateTreeJson(); context.Response.Write(SerializeHelp.ToJson(list)); }
/// <summary> /// 添加 /// </summary> /// <param name="context"></param> public void AddOrderRequest(HttpContext context) { var response = new ResponseMessage(); try { string productId = context.Request.Form["ProductId"]; string userId = context.Request.Form["UserId"]; var exist = _infoService.GetList().Where(y => y.UserId == userId && y.ProductId == productId && y.States == 0).FirstOrDefault(); if (exist != null) { response.code = 101; response.msg = "该商品已加入购物车"; context.Response.Write(SerializeHelp.ToJson(response)); return; } var quantity = context.Request.Form["Quantity"] == null ? 1 : Convert.ToInt32(context.Request.Form["Quantity"]); var total = context.Request.Form["Total"] == null ? 0 : Convert.ToDecimal(context.Request.Form["Total"]); string remark = context.Request.Form["Remark"]; string deliveryId = context.Request.Form["DeliveryId"]; string deliveryDate = context.Request.Form["DeliveryDate"]; //订单 Orders order = new Orders(); order.UserId = userId; order.Total = total * quantity; order.Remark = remark; order.OrdersId = Guid.NewGuid().ToString(); order.Orderdate = DateTime.Now; order.States = 0; //加入购物车未付款 order.DeliveryId = deliveryId; order.DeliveryDate = deliveryDate == null? DateTime.Now: Convert.ToDateTime(deliveryDate); order.ProductId = productId; //订单详情 Detail detail = new Detail { DetailId = Guid.NewGuid().ToString(), OrdersId = order.OrdersId, ProductId = productId, Quantity = quantity, States = 0, UserId = userId }; var add1 = _infoService.Add(order); var add2 = _infodetailService.Add(detail); if (add1 && add2) { response.code = 0; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); return; } response.code = 0; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); return; } catch (Exception e) { response.code = 500; response.msg = "失败,请重试"; context.Response.Write(SerializeHelp.ToJson(response)); } }