Example #1
0
        public string UpdateProduct(MongoProduct product)
        {
            collection.ReplaceOne(p => p.Name == product.Name, product);



            return("Product Price and Manufacturer details is updated successfully");
        }
Example #2
0
        public string  UpdateProduct(MongoProduct product)
        {
            IMongoDbProductRepository mongoRep = new MongoDbProductRepository();
            string res = mongoRep.UpdateProduct(product);

            Console.WriteLine(res);
            Console.WriteLine();
            return(res);
        }
Example #3
0
        public void InsertProduct(MongoProduct product)
        {
            var foundItems = collection.Find <MongoProduct>(x => x.Name == product.Name).Any();

            if (!foundItems)
            {
                collection.InsertOne(product);
            }
        }
        public async Task <IActionResult> PutProducts(string id, MongoProduct product)
        {
            var data = await _mongoProductRepository.Get(id);

            if (data == null)
            {
                return(NotFound());
            }
            await _mongoProductRepository.Update(id, product);

            return(Ok(data));
        }
Example #5
0
        public void GetAllProducts()
        {
            MongoProduct product = new MongoProduct();
            //productRepository = new ProductRepository();
            IMongoDbProductRepository  mongoRep    = new MongoDbProductRepository();
            IEnumerable <MongoProduct> productList = mongoRep.GetAllProducts();

            Console.WriteLine("********Products details************");
            foreach (var products in productList)
            {
                Console.WriteLine($"Name : {products.Name} , ProductId:{products.Id} ,Price: {products.Price}, ManufacturerDetails : {products.ManufacturerDetails.ManufacturerName} ,ManufacturerDetails : {products.ManufacturerDetails.Place}, ManufacturerDetails : {products.ManufacturerDetails.PhoneNumber}");
            }
        }
Example #6
0
        public void GetByProductId(string productId)
        {
            IMongoDbProductRepository mongoRep = new MongoDbProductRepository();
            MongoProduct prodts = mongoRep.GetByProductId(productId);

            if (prodts != null)
            {
                Console.WriteLine();
                Console.WriteLine("******Matched record by ProductId*****" + "\n"
                                  + "Name:" + prodts.Name + "," + "Price:" + prodts.Price + "," + "ProductID:" + prodts.Id + "," + "ManufacturerName:" + prodts.ManufacturerDetails.ManufacturerName + "," + "Place:" + prodts.ManufacturerDetails.Place + "," + "PhoneNumber:" + prodts.ManufacturerDetails.PhoneNumber);
            }
            else
            {
                Console.WriteLine("No matched records found for the productID:{0}:" + productId);
            }
        }
Example #7
0
 public string RemoveProduct(MongoProduct product)
 {
     collection.DeleteOne(s => s.Name == product.Name);
     return("Product is removed successfully :" + product.Name);
 }
Example #8
0
        public MongoProduct GetByProductId(string productId)
        {
            MongoProduct record = collection.Find(Builders <MongoProduct> .Filter.Eq(x => x.Id, productId)).FirstOrDefault();

            return(record);
        }
        public async Task <ActionResult <MongoProduct> > PostProducts(MongoProduct product)
        {
            await _mongoProductRepository.Add(product);

            return(Ok(product));
        }
        static void Main(string[] args)
        {
            var serialList = new XmlSerializer(typeof(List <MongoProduct>));
            var serial     = new XmlSerializer(typeof(MongoProduct));
            var path       = @"..\..\..\data\";

            var list = new List <MongoProduct>();

            using (var fs = File.OpenRead(path + "products.xml")) {
                list = serialList.Deserialize(fs) as List <MongoProduct>;
            }


            //must be done first
            var collection = Collections.ProductCollection;


            //LoadMongoData(list);

            //PopulateSqlDatabase(list);

            //Lets find and Modify

            //CreateMongoDbOrder();
            CreateSqlOrder();

            //AddColumn();
            //RemoveColumn();
            //UpdateDocumentsWithNewKeyword();
            //UpdateAllDocuments();
            //FindAndModify();

            //list.First().ASIN;

            var asinName = "B00000J1TX";

            var query = Query <MongoProduct>
                        .Where(item => item.ASIN == asinName);

            var asin = Collections.ProductCollection.FindOne(query);

            //query = Query<MongoProduct>.Where(item => item.ListPriceInteger < 9.99m * 10000);
            //var itemsUnder999 = Collections.ProductCollection.FindAs<MongoProduct>(query).ToList();

            Collections.ProductCollection.Distinct("Title", query);

            query = Query <MongoProduct> .Where(item => item.PackageDimensions.Weight < .1m);

            var itemsVeryLight = Collections.ProductCollection.FindAs <MongoProduct>(query).ToList();

            Collections.ProductCollection.Find(query).SetSortOrder(SortBy <MongoProduct> .Ascending(item => item.Title));

            //var query = Query<MongoProduct>.Where(item => item.ListPrice < 4.99m);
            //var count = Collections.ProductCollection.Count(query);

            //Collections.ProductCollection.FindAll();

            //does work
            var asin2 = Collections.ProductCollection.Find(query).SetFields(Fields.Include("listPrice", "title")).FirstOrDefault();
            //does not work
            var asin2a = Collections.ProductCollection.Find(query).SetFields(Fields.Include("ListPriceInteger", "Title")).FirstOrDefault();

            //must be the c# class properties.
            var asin3 = Collections.ProductCollection.Find(query).SetFields(Fields <MongoProduct> .Include(c => c.ListPriceInteger, c => c.Title)).FirstOrDefault();

            var product = new MongoProduct()
            {
            };

            //Collections.ProductCollection.Save<MongoProduct>(product);

            System.Console.ReadLine();
        }
Example #11
0
        private async void mongodb_1000migrate_Click(object sender, EventArgs e)
        {
            LoadProgressText.Text = "Mongo 1000 Load in Progress";
            //Read Files//
            var path     = secondPath.Text;
            var row      = string.Empty;
            var products = new List <MongoProduct>();

            using (var fs = new FileStream(path, FileMode.Open))
                using (var sr = new StreamReader(fs, Encoding.UTF8))
                {
                    while (null != (row = sr.ReadLine()))
                    {
                        var pieces = row.Split(';');
                        var p      = new MongoProduct()
                        {
                            ProductID    = int.Parse(pieces[0]),
                            ProductName  = pieces[1],
                            UnitPriceHUF = int.Parse(pieces[2]),
                            Category     = pieces[3]
                        };
                        products.Add(p);
                    }
                }
            //Load Database//
            var client   = new MongoClient("mongodb://localhost:27017");
            var database = client.GetDatabase("demo");
            var collec   = database.GetCollection <BsonDocument>("Products");
            var sometime = new List <long>();

            for (int i = 0; i < products.Count; i = i + 1000)
            {
                var items          = products.Skip(i).Take(1000);
                var sw             = new Stopwatch();
                var EmptyInfoArray = new List <BsonDocument>();
                sw.Start();
                foreach (var item in items)
                {
                    var document = new BsonDocument {
                        { "_id", item.ProductID },
                        { "ProductName", item.ProductName },
                        { "UnitPriceHUF", item.UnitPriceHUF },
                        { "Category", item.Category }
                    };
                    EmptyInfoArray.Add(document);
                }
                await collec.InsertManyAsync(EmptyInfoArray);

                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds.ToString());
                sometime.Add(sw.ElapsedMilliseconds);
            }
            //Write TXT//
            using (var streamw = new StreamWriter("1000_load_mongodb.txt"))
            {
                foreach (var item in sometime)
                {
                    streamw.WriteLine(item);
                }
                streamw.Close();
            }
            LoadProgressText.Text = "Nothing in Progress";
            MessageBox.Show("Finished");
        }