Ejemplo n.º 1
0
        public IMessageProvider Create()
        {
            var serialNo = SerialNoHelper.Create();

            // InnerObject.AccountLevel = AccountLevel;
            InnerObject.State = PointRebateStates.Normal;
            CommodityService.Create(InnerObject);
            AddMessage("success", InnerObject.DisplayName);
            Logger.LogWithSerialNo(LogTypes.CommodityCreate, serialNo, InnerObject.CommodityId, InnerObject.DisplayName);

            return(this);
        }
Ejemplo n.º 2
0
        public IActionResult UploadCommodity()       //上传商品
        {
            var    date            = Request;
            var    files           = Request.Form.Files; //上传的图片
            var    data            = Request.Form;       //上传的信息
            long   size            = files.Sum(f => f.Length);
            string webRootPath     = _hostingEnvironment.WebRootPath;
            string contentRootPath = _hostingEnvironment.ContentRootPath;

            foreach (var formFile in files)
            {
                if (formFile.Length > 0)                                    //上传图片成功
                {
                    long fileSize = formFile.Length;                        //获得文件大小,以字节为单位

                    var exetent     = Path.GetExtension(formFile.FileName); //文件后缀名
                    var shopDicName = webRootPath + "/uploads/shops/1";     //+ Request.Cookies["shopName"].ToString();
                    if (!Directory.Exists(shopDicName))
                    {
                        //新建对应的文件夹
                        Directory.CreateDirectory(shopDicName);
                    }
                    string newFileName = System.Guid.NewGuid().ToString();            //随机生成新的文件名
                    var    filePath    = shopDicName + "/" + newFileName + exetent;   //newFileName;
                    var    url         = "/uploads/shops/1/" + newFileName + exetent; //存入数据库中实际的内容

                    //新建商品
                    if (commodityService.Create(decimal.Parse(data["price"]), data["category"], data["description"], int.Parse(data["storage"])
                                                , data["name"], "1", url))
                    {
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            formFile.CopyTo(stream);
                        }
                    }
                }
            }
            return(Ok(new { count = files.Count, size }));
        }