public void LeaveReview(String reviewText, String userName, int productId) { using (var context = new TackleHackSQLContext()) { var review = new Review() { Text = reviewText, UserName = userName, DateTime = new DateTime(), }; context.Review.Add(review); context.SaveChanges(); var productReview = new ProductReview() { ReviewId = review.Id, ProductId = productId }; context.ProductReview.Add(productReview); context.SaveChanges(); } }
public static void Initialize() { using (var context = new TackleHackSQLContext()) { if (context.Account.Count() == 0) { var account = new Account() { Name = "Demo", Description = "Account for demo" }; context.Account.Add(account); context.SaveChanges(); } } }
public static void ProcessVendorProducts(int vendorId, String filePath) { using (var context = new TackleHackSQLContext()) { DataTable vendorData = ReadFileToDataTable(filePath); var columnNames = vendorData.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToList(); var featureColumns = columnNames.Where(x => x.Contains("Key_Feature")); foreach (DataRow row in vendorData.Rows) { var product = new Product() { BrandName = (String)row["BRAND"], ItemNumber = (String)row["SKU"], Sku = (String)row["SKU"], ProductName = (String)row["Product Name"], Description = (String)row["Product Description"], Msrp = (double)row["Price"], VendorId = vendorId }; context.Product.Add(product); context.SaveChanges(); foreach (String column in featureColumns) { var description = (row[column] == DBNull.Value ? string.Empty : (String)row[column]); if (!String.IsNullOrEmpty(description)) { var feature = context.Feature.Where(x => x.Description.Equals(description)).FirstOrDefault(); if (feature == null) { feature = new Feature() { Description = description }; context.Feature.Add(feature); context.SaveChanges(); } var productFeature = new ProductFeature() { ProductId = product.Id, FeatureId = feature.Id }; context.ProductFeature.Add(productFeature); context.SaveChanges(); } } var videoLink = (row["Video"] == DBNull.Value ? string.Empty : (String)row["Video"]); if (!String.IsNullOrEmpty(videoLink)) { var media = new Media() { Title = product.ProductName, Link = videoLink, ProductId = product.Id }; context.Media.Add(media); context.SaveChanges(); } } } }