Ejemplo n.º 1
0
		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();
		}
Ejemplo n.º 2
0
		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();
		}
Ejemplo n.º 3
0
		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);
		}