public async void Add(ILanni.FarmMarket.Models.Product product)
 {
     var dbModel    = AutoMapper.Mapper.Map <Product>(product);
     var db         = Client.GetDatabase("test");
     var collection = db.GetCollection <Product>("product");
     await collection.InsertOneAsync(dbModel, new InsertOneOptions()
     {
         BypassDocumentValidation = true
     });
 }
Beispiel #2
0
        public IActionResult Add()
        {
            ILanni.FarmMarket.Models.Product p = new ILanni.FarmMarket.Models.Product()
            {
                Id   = DateTime.Now.Ticks,
                Area = new List <string>()
                {
                    "广东省", "韶关市", "乐昌市"
                },
                Areacode = new List <string>()
                {
                    "广东省", "韶关市", "乐昌市"
                },
                Category = new List <string>()
                {
                    "水果", "马蹄"
                },
                Categorycode = new List <string>()
                {
                    "水果", "马蹄"
                },
                Desc     = "乐昌北乡马蹄,个大,柔嫩,爽甜",
                Keywords = new List <string>()
                {
                    "马蹄", "北乡", "贡品"
                },
                Name     = "北乡马蹄",
                Position = new[] { 102.21f, 35.21f },
                Sptype   = "北乡马蹄",
                Summary  = "北乡马蹄",
                Title    = "北乡马蹄"
            };

            /*var db = mClient.GetDatabase("test");
             * var collection = db.GetCollection<Product>("product");
             * await collection.InsertOneAsync(p, new InsertOneOptions() { BypassDocumentValidation = true });*/
            service.Add(p);
            var response = new { ok = true };

            /*var response = await client.IndexAsync(p);
             * if (response.IsValid)
             * {
             *   return RedirectToAction("Details", new { id = p.Id });
             * }*/
            return(View("JContainer", JObject.FromObject(response)));
        }