public static void Initialize(ECommerceContext context) { context.Database.EnsureCreated(); if (context.GeneralProduct.Any()) { return; // DB has been seeded } var productList = getImageUrl(); foreach (var eachProduct in productList) { //factory pattern, you give it a parameter, it will return you a object var productObject = ProductFactory.CreateProcut(eachProduct); Console.WriteLine(productObject); if (productObject.GetType() == typeof(GlassProduct)) { GlassProduct additionProduct = (GlassProduct)productObject; context.GlassProduct.Add(additionProduct); } else if (productObject.GetType() == typeof(GeneralProduct)) { GeneralProduct additionProduct = (GeneralProduct)productObject; context.GeneralProduct.Add(additionProduct); } } context.SaveChanges(); }
public ActionResult Delete(GeneralProduct generalProduct) { if (ModelState.IsValid) { GeneralProductService.Delete(generalProduct); return(RedirectToAction("Index")); } return(View(generalProduct)); }
public static IProduct CreateProcut(GeneralProduct input) { if (input.caption.Contains("glass")) { if (input.caption.Contains("etching")) { return(new GlassProduct() { likes = 0, id = input.id, caption = input.caption, Addtions = "None", media_url = input.media_url, Silhouette = "Ford", timestamp = input.timestamp }); } else { return(new GlassProduct() { likes = 0, id = input.id, caption = input.caption, Addtions = "vial, moss", media_url = input.media_url, Silhouette = "Dragon", timestamp = input.timestamp }); } } else { return(new GeneralProduct() { likes = 0, id = input.id, caption = input.caption, media_url = input.media_url, timestamp = input.timestamp }); } }
public static List <GeneralProduct> getImageUrl() { var allImages = new List <GeneralProduct>(); var result = InstaData.retriveList(); List <Task <string> > requestUrlTasks = new List <Task <string> >(); foreach (var eachUrl in result) { var task = Task.Run(async() => await GetImagesList(eachUrl)); requestUrlTasks.Add(task); } Task.WaitAll(requestUrlTasks.ToArray()); foreach (var eachTask in requestUrlTasks) { var reachResult = eachTask.Result; GeneralProduct items = JsonConvert.DeserializeObject <GeneralProduct>(reachResult); allImages.Add(items); } return(allImages); }
public GeneralProductAssertions(GeneralProduct value) : base(value) { }
public static GeneralProductAssertions Should(this GeneralProduct instance) => new GeneralProductAssertions(instance);