public static void UpdateProduct(Product product) { using (CatalogDataContext dc = new CatalogDataContext()) { var originalProduct = dc.GetTable <Product>().SingleOrDefault(p => p.ProductID.Equals(product.ProductID)); originalProduct.Name = product.Name; originalProduct.ProductNumber = product.ProductNumber; originalProduct.MakeFlag = product.MakeFlag; originalProduct.FinishedGoodsFlag = product.FinishedGoodsFlag; originalProduct.Color = product.Color; originalProduct.SafetyStockLevel = product.SafetyStockLevel; originalProduct.ReorderPoint = product.ReorderPoint; originalProduct.StandardCost = product.StandardCost; originalProduct.ListPrice = product.ListPrice; originalProduct.Size = product.Size; originalProduct.SizeUnitMeasureCode = product.SizeUnitMeasureCode; originalProduct.WeightUnitMeasureCode = product.WeightUnitMeasureCode; originalProduct.Weight = product.Weight; originalProduct.DaysToManufacture = product.DaysToManufacture; originalProduct.ProductLine = product.ProductLine; originalProduct.Class = product.Class; originalProduct.Style = product.Style; originalProduct.ProductSubcategoryID = product.ProductSubcategoryID; originalProduct.ProductModelID = product.ProductModelID; originalProduct.SellStartDate = product.SellStartDate; originalProduct.SellEndDate = product.SellEndDate; originalProduct.DiscontinuedDate = product.DiscontinuedDate; originalProduct.ModifiedDate = DateTime.Today; dc.SubmitChanges(); } }
public static Product GetProductById(int id) { using (CatalogDataContext dc = new CatalogDataContext()) { return(dc.GetTable <Product>().SingleOrDefault(p => p.ProductID.Equals(id))); } }
public MainWindow() { InitializeComponent(); catalog = new CatalogDataContext(); var products = from p in catalog.Products select p; ProductsGrid.ItemsSource = products; }
public static void DeleteProductId(int id) { using (CatalogDataContext dc = new CatalogDataContext()) { var answer = dc.GetTable <Product>().First(e => e.ProductID == id); dc.Products.DeleteOnSubmit(answer); dc.SubmitChanges(); } }
public static IEnumerable <Product> GetAllProducts() { using (CatalogDataContext dc = new CatalogDataContext()) { Table <Product> products = dc.GetTable <Product>(); IQueryable <Product> answer = (from product in products select product); return(answer.ToList()); } }
public static void InsertNewProduct(Product product) { using (CatalogDataContext dc = new CatalogDataContext()) { product.ModifiedDate = DateTime.Now; product.rowguid = Guid.NewGuid(); dc.Products.InsertOnSubmit(product); dc.SubmitChanges(); } }
public static async Task Main(string[] args) { var logger = Log.Logger = new LoggerConfiguration() //.MinimumLevel.Debug() .WriteTo.Async(w => w.File("logs.json", rollingInterval: RollingInterval.Hour, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} #{ThreadId} {NewLine}{Exception}")) .Enrich.WithThreadId() .CreateLogger(); string connectionString = "mongodb://localhost:27017"; string database = "CatalogDb"; CatalogDataContext catalogDataContext = new CatalogDataContext( connectionString, database); var scheduler = new AmazonTaskScheduler <Book>(catalogDataContext); var skipArgs = int.Parse(args[0]); var takeArgs = int.Parse(args[1]); Console.WriteLine($"Processing skip:{skipArgs}, taking:{takeArgs}"); Log.Information("{0}", skipArgs); Log.Information("{0}", takeArgs); try { if (skipArgs >= 0 && takeArgs > 0) { var urls = SetUpURLs(); int skip = skipArgs;//abcdefghijklmnopqrstuvwxy int take = takeArgs; var urls_part = urls.Skip(skip).Take(take).ToList(); var urlsProcessed = await scheduler.ScheduleWithSemaphore(urls_part); //var urlsProcessed = await scheduler.ScheduleSingleThread(urls_part); Console.WriteLine($"Processed {urlsProcessed}/{urls_part.Count} urls."); } else { Console.WriteLine("invalid input..."); } } catch (Exception ex) { Log.Error(ex, "{exception}"); Console.WriteLine($"Exception: {ex.Message}"); } Console.Read(); }
public void DivideProductsOnPagesTest() { using (CatalogDataContext dc = new CatalogDataContext()) { List <Product> list = dc.GetTable <Product>().ToList(); List <List <Product> > res = list.DivideProductsOnPages(5, 5); Assert.AreEqual(res.Count(), 5); Assert.AreEqual(res[0].Count(), 5); } }
public static string GetProductVendorByProductName(string productName) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <ProductVendor> productVendors = dc.GetTable <ProductVendor>(); List <string> vendors = (from productVendor in productVendors where productVendor.Product.Name.Equals(productName) select productVendor.Vendor.Name).ToList(); return(vendors[0]); } }
public static List <Product> GetProductsByVendorName(string vendorName) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <ProductVendor> productsVendors = dc.GetTable <ProductVendor>(); List <Product> answer = (from productVendor in productsVendors where productVendor.Vendor.Name.Equals(vendorName) select productVendor.Product).ToList(); return(answer); } }
public static int GetTotalStandardCostByCategory(ProductCategory category) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <Product> productsTable = dc.GetTable <Product>(); decimal sum = (from product in productsTable where product.ProductSubcategory.ProductCategory.Name.Equals(category.Name) select product.StandardCost).ToList().Sum(); return((int)sum); } }
public static List <Product> GetNRecentlyReviewedProducts(int howManyProducts) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <ProductReview> productReviews = dc.GetTable <ProductReview>(); List <Product> products = (from productReview in productReviews orderby productReview.ReviewDate descending select productReview.Product ).Take(howManyProducts).ToList(); return(products); } }
public static List <Product> GetProductsWithNRecentReviews(int howManyReviews) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <Product> productsTable = dc.GetTable <Product>(); List <Product> products = (from product in productsTable where product.ProductReviews.Count == howManyReviews select product).ToList(); return(products); } }
public static List <Product> GetProductsByName(string namePart) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <Product> productsTable = dc.GetTable <Product>(); List <Product> products = (from product in productsTable where product.Name.Contains(namePart) select product).ToList(); return(products); } }
public static List <Product> GetNProductsFromCategory(string categoryName, int n) { using (CatalogDataContext dc = new CatalogDataContext()) { Table <Product> productsTable = dc.GetTable <Product>(); List <Product> products = (from product in productsTable where product.ProductSubcategory.ProductCategory.Name.Equals(categoryName) select product).Take(n).ToList(); return(products); } }
public void GetProductsWithoutCategoryTest() { using (CatalogDataContext dc = new CatalogDataContext()) { List <Product> list = dc.GetTable <Product>().ToList(); List <Product> resLINQ = list.GetProductsWithoutCategoryLINQ(); List <Product> res = list.GetProductsWithoutCategory(); Assert.AreEqual(res.Count(), 209); Assert.AreEqual(resLINQ.Count(), 209); Assert.AreEqual(resLINQ[2].ProductNumber, res[2].ProductNumber); Assert.AreEqual(resLINQ[2], res[2]); Assert.AreEqual(res[2].ProductNumber, "BE-2349"); } }
public void GetProductVendorStringTest() { using (CatalogDataContext dc = new CatalogDataContext()) { List <Product> list = dc.GetTable <Product>().ToList(); string resLINQ = list.GetProductVendorStringLINQ(); string res = list.GetProductVendorString(); string lineLINQ = resLINQ.Split('\n')[2]; string line = res.Split('\n')[2]; Assert.AreEqual(line, lineLINQ); Assert.AreEqual(line, "Headset Ball Bearings-American Bicycles and Wheels"); } }
public DeleteTests() { AppSettings appSettings = new AppSettings { IsTest = true }; var options = new Mock <IOptionsSnapshot <AppSettings> >(); options.Setup(x => x.Value).Returns(appSettings); dataContext = new CatalogDataContext(options.Object); dataContext.Products.AddRange(new List <Product> { new Product { Id = id } }); }
public void FilterPersonsByLastName_AnonymousTypeClass() { using (CatalogDataContext _newCatalog = new CatalogDataContext(m_ConnectionString)) { try { _newCatalog.AddContent(TestDataGenerator.PrepareData()); string _filtered = _newCatalog.FilterPersonsByLastName_AnonymousType("Person"); Assert.AreEqual("First, Second, Mister", _filtered); } finally { _newCatalog.TruncateAllData(); } } }
public static string GetProductVendorString(this List <Product> products) { string tmp = ""; using (CatalogDataContext dc = new CatalogDataContext()) { Table <ProductVendor> productVendors = dc.GetTable <ProductVendor>(); var answer = products.Join(productVendors, product => product.ProductID, productVendor => productVendor.ProductID, (product, productVendor) => new { ProductName = product.Name, VendorName = productVendor.Vendor.Name }).ToList(); foreach (var s in answer) { tmp += s.ProductName + "-" + s.VendorName + "\n"; } } return(tmp); }
public static string GetProductVendorStringLINQ(this List <Product> products) { string tmp = ""; using (CatalogDataContext dc = new CatalogDataContext()) { Table <ProductVendor> productVendors = dc.GetTable <ProductVendor>(); var answer = (from product in products join productVendor in productVendors on product.ProductID equals productVendor.ProductID where productVendor.ProductID.Equals(product.ProductID) select new { ProductName = product.Name, VendorName = productVendor.Vendor.Name }).ToList(); foreach (var s in answer) { tmp += s.ProductName + "-" + s.VendorName + "\n"; } } return(tmp); }
public void CatalogConstructorTest() { using (CatalogDataContext _newCatalog = new CatalogDataContext(m_ConnectionString)) { Assert.IsNotNull(_newCatalog.Connection); Assert.AreEqual <int>(0, _newCatalog.Persons.Count()); Assert.AreEqual <int>(0, _newCatalog.CDCatalogEntities.Count()); try { _newCatalog.AddContent(TestDataGenerator.PrepareData()); Assert.AreEqual <int>(3, _newCatalog.Persons.Count()); Assert.AreEqual <int>(15, _newCatalog.CDCatalogEntities.Count()); } finally { _newCatalog.TruncateAllData(); } } }
public void FilterPersonsByLastName_QuerySyntaxTest() { using (CatalogDataContext _newCatalog = new CatalogDataContext(m_ConnectionString)) { try { _newCatalog.AddContent(TestDataGenerator.PrepareData()); IEnumerable <Person> _filtered = _newCatalog.FilterPersonsByLastName_QuerySyntax("Person"); Type _returnedType = _filtered.GetType(); Assert.AreEqual <string>("System.Data.Linq.DataQuery`1", $"{_returnedType.Namespace}.{_returnedType.Name}"); Assert.AreEqual <string>("SELECT [t0].[Id], [t0].[FirstName], [t0].[LastName], [t0].[Age]\r\nFROM [dbo].[Person] AS [t0]\r\nWHERE [t0].[LastName] = @p0", _filtered.ToString().Trim()); Assert.AreEqual(2, _filtered.Count()); foreach (Person p in _filtered) { Assert.AreEqual("Person", p.LastName); } } finally { _newCatalog.TruncateAllData(); } } }
public void FilterPersonsByLastName_ForEachTest() { using (CatalogDataContext _newCatalog = new CatalogDataContext(m_ConnectionString)) { try { _newCatalog.AddContent(TestDataGenerator.PrepareData()); IEnumerable <Person> _filtered = _newCatalog.FilterPersonsByLastName_ForEach("Person"); Type _returnedType = _filtered.GetType(); Assert.AreEqual <string>("System.Collections.Generic.List`1", $"{_returnedType.Namespace}.{_returnedType.Name}"); Assert.AreEqual <string>("System.Collections.Generic.List`1[TP.StructuralData.LINQ_to_SQL.Person]", _filtered.ToString(), _filtered.ToString()); Assert.AreEqual(2, _filtered.Count()); foreach (Person p in _filtered) { Assert.AreEqual("Person", p.LastName); } } finally { _newCatalog.TruncateAllData(); } } }
public MyProductDataContext(CatalogDataContext catalogDataContext) { myProducts = catalogDataContext.GetTable <Product>().Select(p => new MyProduct(p)).ToList(); }
public Handler(CatalogDataContext dataContext, IMapper mapper) { this.dataContext = dataContext; this.mapper = mapper; }
public ProductRepository(CatalogDataContext context) { _context = context; }
public Handler(CatalogDataContext dataContext) { this.dataContext = dataContext; }
public CategoryRepository(CatalogDataContext dbContext) { _dbContext = dbContext; }
public AmazonTaskScheduler( CatalogDataContext context) { _context = context; }