コード例 #1
0
        //private static readonly string url = System.Web.HttpContext.Current.Request.UrlReferrer.GetLeftPart(UriPartial.Authority);
        //Guid cid = WebSitesService.instance().GetCompanyIDByHTTP(url);
        /// <summary>
        /// 获取分页
        /// </summary>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页显示多少条</param>
        /// <param name="wheres">查询条件</param>
        /// <param name="sortorder">倒序/正序</param>
        /// <param name="sortname">排序字段</param>
        /// <returns></returns>
        public HttpResponseMessage Get(int pageIndex, int pageSize, string wheres, string sortorder, string sortname)
        {
            int totalcount = 0;
            IEnumerable <Product> datalist = ProductService.instance().GetPageByDynamic(pageIndex, pageSize, out totalcount, sortname, sortorder, wheres);

            if (datalist.Count() > 0)
            {
                datalist.ToList().ForEach(m =>
                {
                    m.Attr = Product_AttService.GetAttsByPID(m.ID);
                });
            }
            ResultBase_Page page = new ResultBase_Page(pageIndex, pageSize, totalcount);

            page.content = datalist;
            return(Util.Utils.ConvertToJson(page));
        }
コード例 #2
0
        public JsonResult Product_Async(string id)
        {
            Hashtable      hash  = new Hashtable();
            Guid           ID    = new Guid(id);
            List <Product> plist = ProductService.instance().GetProductByCid(ID).ToList();

            foreach (var p in plist)
            {
                if (string.IsNullOrEmpty(p.itemid))
                {
                    product_item entity = new product_item();
                    entity.item_name = Utils.DropHTML(p.Description);
                    entity.price     = p.Attr.First().price.Price.ToString();
                    entity.stock     = p.Attr.First().price.Stock.ToString();
                    entity.imgs      = new List <string>();
                    entity.cate_ids  = new List <string>()
                    {
                        ClassService.instance().Single(p.ClassID).cate_id
                    };
                    entity.skus          = new List <skus>();
                    entity.merchant_code = "";
                    foreach (var item in FilesService.instance().GetFilesByRelationID(p.ID))
                    {
                        string reulst_msg = WSApi.upload(GetToken(), item.FilePath);
                        if (Utils.GetJsonValue(reulst_msg, "status_code") == "0")
                        {
                            string imgurl = Utils.GetJsonValue(reulst_msg, "result");
                            if (imgurl.Split('?').Length > 0)
                            {
                                entity.imgs.Add(imgurl.Split('?')[0]);
                            }
                            else
                            {
                                entity.imgs.Add(imgurl);
                            }
                        }
                    }
                    foreach (var item in Product_AttService.GetAttsByPID(ID))
                    {
                        entity.skus.Add(new skus()
                        {
                            price             = item.price.Price.ToString(),
                            sku_merchant_code = "",
                            stock             = item.price.Stock.ToString(),
                            title             = item.key.Name + ":" + item.val.Value
                        });
                    }
                    ;
                    string json        = WSApiJson.vdian_item_add(entity);
                    string msg         = WSApi.vdian_item_add(GetToken(), json);
                    string status_code = Utils.GetJsonValue(msg, "status_code");
                    if (status_code == "0")
                    {
                        p.itemid = Utils.GetJsonValue(msg, "itemid");
                        p.opt    = "1";
                        ProductService.instance().Update(p);
                    }
                    else
                    {
                        hash[p.Title] = Utils.GetJsonValue(msg, "status_reason");
                    }
                }
            }
            return(Json(hash, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public JsonResult Product(FormCollection form)
        {
            ResultBase_form result = new ResultBase_form();
            Guid            ID     = new Guid(form["ID"]);
            Product         p      = ProductService.instance().Single(ID);

            if (!string.IsNullOrEmpty(p.itemid))
            {
                string del_msg = WSApi.vdian_item_delete(GetToken(), p.itemid);
                if (Utils.GetJsonValue(del_msg, "status_code") != "0")
                {
                    result.msg = Utils.GetJsonValue(del_msg, "status_reason");
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            product_item entity = new product_item();

            entity.item_name = form["Description"];
            entity.price     = form["Price"];
            entity.stock     = form["Stock"];
            entity.imgs      = new List <string>();
            entity.cate_ids  = new List <string>()
            {
                form["cate_ids"]
            };
            entity.skus          = new List <skus>();
            entity.merchant_code = "";
            foreach (var item in FilesService.instance().GetFilesByRelationID(ID))
            {
                string reulst_msg = WSApi.upload(GetToken(), item.FilePath);
                if (Utils.GetJsonValue(reulst_msg, "status_code") == "0")
                {
                    string imgurl = Utils.GetJsonValue(reulst_msg, "result");
                    if (imgurl.Split('?').Length > 0)
                    {
                        entity.imgs.Add(imgurl.Split('?')[0]);
                    }
                    else
                    {
                        entity.imgs.Add(imgurl);
                    }
                }
            }
            foreach (var item in Product_AttService.GetAttsByPID(ID))
            {
                entity.skus.Add(new skus()
                {
                    price             = item.price.Price.ToString(),
                    sku_merchant_code = "",
                    stock             = item.price.Stock.ToString(),
                    title             = item.key.Name + ":" + item.val.Value
                });
            }
            ;
            string json = WSApiJson.vdian_item_add(entity);
            string msg  = WSApi.vdian_item_add(GetToken(), json);

            result.status = Convert.ToInt32(Utils.GetJsonValue(msg, "status_code"));
            if (result.status == 0)
            {
                p.itemid = Utils.GetJsonValue(msg, "itemid");
                p.opt    = "1";
                ProductService.instance().Update(p);
            }
            result.msg       = result.status == 0 ? "操作成功" : "操作失败";
            result.ResultURL = "/WeShop/Product/" + p.ID;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }