using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; using MisIngredientesVue.Core.Models; using MisIngredientesVue.Core.Services; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace MisIngredientesVue.Controllers { [AllowAnonymous] [Route("api/[controller]")] [ApiController] public class TestController : Controller { private readonly IRepository _repository; public TestController(IRepository repository) { _repository = repository; } [HttpGet] public async Task Test() { return Ok(); //return Ok(); //await _repository.Insert(new Product() { Name = "Prueba4", Qty = 12, SalePrice = 12, SupplierCost = 23, UnitId = 1 }); //var response = await _repository.Find(null, 0, 0, ""); // //await _repository.DeleteMany(new Product[] { new Product() { Id = 1 } }); // return Ok(); // var client = new MongoClient( // "mongodb://admin:vxZCJXyNEdnIbTuQ@printerparts-shard-00-00-onhce.mongodb.net:27017,printerparts-shard-00-01-onhce.mongodb.net:27017,printerparts-shard-00-02-onhce.mongodb.net:27017/test?ssl=true&replicaSet=printerparts-shard-0&authSource=admin" // ); // var mongoDatabase = client.GetDatabase("main"); // var res = await mongoDatabase.GetCollection("products").FindAsync(new BsonDocument("_tid", new ObjectId("5b58dd0e0ec7430ab6073bd3"))); // var list = await res.ToListAsync(); //// System.IO.File.WriteAllText(@"C:\\3DS\\test.txt", JsonConvert.SerializeObject(list)); // foreach (var item in list) // { // var unit = Convert.ToInt32(item["unit"].ToString()); // if (unit == 90) // unit = 1; // else unit += 1; // try // { // var rawTaxes = item["taxes"]; // //var taxes = new List(); // //if(!rawTaxes.IsBsonNull) // //{ // // foreach(var t in rawTaxes.AsBsonArray) // // { // // taxes.Add(new ProductTax() { Name = t["name"].ToString(), Pc = (decimal)t["pc"].AsInt32 }); // // } // //} // await _repository.Insert("test", 1, new Product() // { // Name = item["description"].ToString(), // Buyer = item["buyer"]?.ToString(), // Supplier = item["supplier"]?.ToString(), // PurchaseZone = item["zone"]?.ToString(), // Category = item["category"]?.ToString(), // Code = item["codes"].AsBsonArray[0]?.ToString(), // ClaveProductoSat = item["sat_claveproducto"]?.ToString(), // ClaveUnidadSat = item["sat_claveunidad"]?.ToString(), // MinQty = item["minstock"].IsBsonNull ? null : (decimal?)(Convert.ToDecimal(item["minstock"]) / 1000M), // //WholesalePrice = item["wholesaleprice"].IsBsonNull ? null : (decimal?)(Convert.ToDecimal(item["wholesaleprice"]) / 100M), // //WholesaleQty = item["wholesaleqty"].IsBsonNull ? null : (decimal?)(Convert.ToDecimal(item["wholesaleqty"]) / 1000M), // SalePriceRate = item["salepricerate"].IsBsonNull ? null : (decimal?)(Convert.ToDecimal(item["salepricerate"]) / 100M), // Qty = item["stock"].IsBsonNull ? null : (decimal?)(Convert.ToDecimal(item["stock"]) / 1000M), // SalePrice = Convert.ToDecimal(item["saleprice"]) / 100M, // SupplierCost = Convert.ToDecimal(item["supplierprice"]) / 100M, // UnitId = unit, // Iva = 0, // Ieps = 0 // //Taxes = taxes // }); // } // catch // { // } // } // return Ok(); //db.getCollection('products').find({_tid: ObjectId("5b58dd0e0ec7430ab6073bd3")}) } } }