public void Delete(Product prd) { if (string.IsNullOrWhiteSpace(prd._id)) return; var filter = Builders<BsonDocument>.Filter.Eq("_id", new ObjectId(prd._id)); var update = Builders<BsonDocument>.Update.Set("Status", 1); _collection.UpdateOneAsync(filter, update).Wait(); }
public void Modify(Product prd) { if (string.IsNullOrWhiteSpace(prd._id)) return; var filter = Builders<BsonDocument>.Filter.Eq("_id", new ObjectId(prd._id)); var update = Builders<BsonDocument>.Update.Set("Type", prd.Type) .Set("Name", prd.Name).Set("Price", prd.Price).Set("LinkUrl", prd.LinkUrl).CurrentDate("UpdateDate"); _collection.UpdateOneAsync(filter, update).Wait(); }
public void Add(Product prd) { var now = DateTime.Now; prd.Status = (int)PrdStatus.active; prd.CreateDate = now; prd.UpdateDate = now; var bsonDoc = prd.ToBson(); var task = _collection.InsertOneAsync(bsonDoc); task.Wait(); }
//[TestMethod] public void AddProduct() { // Arrange Product prd = new Product() { Type = 3, Name = "ccc", Price = 11, LinkUrl = "http://www.bb.com" }; ProductRepository repository = new ProductRepository(); repository.Add(prd); }