예제 #1
0
        /// <summary>
        /// 订单列表获取数据
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public HttpResponseMessage GetOrders()
        {
            string userHostAddress = HttpContext.Current.Request.UserHostAddress;

            if (string.IsNullOrEmpty(userHostAddress))
            {
                userHostAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }

            //最后判断获取是否成功,并检查IP地址的格式(检查其格式非常重要)
            if (!string.IsNullOrEmpty(userHostAddress) && IsIP(userHostAddress))
            {
                return(Utity.toJson(userHostAddress));
            }
            return(Utity.toJson(""));

            //OrderManageDbContext db = new OrderManageDbContext();
            //List<Order> data = db.Orders.Where(u => u.Id > 0).ToList();

            //var tempTotal = data.Count;

            //// 分页查询
            //var tempRows = data.Skip(offset).Take(limit).ToList();
            //ResultData result = new ResultData()
            //{
            //    total = tempTotal,
            //    rows = tempRows
            //};
            //return Utity.toJson(result);
        }
예제 #2
0
        public HttpResponseMessage PostOrder(Order order)
        {
            if (!ModelState.IsValid)
            {
                var a = ModelState.Values.SelectMany(v => v.Errors).ToList();
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
            bool succeed = false;

            if (OrderExists(order.Id))
            {
                succeed = UpdateOrder(order);
            }
            else
            {
                succeed = AddOrder(order);
            }

            if (succeed)
            {
                HttpResponseMessage response = Utity.toJson(order);
                response.Headers.Add("Access-Control-Allow-Origin", "*");
                response.Headers.Add("Access-Control-Allow-Methods", "POST");
                response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type");
                return(response);
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }