public static void Remove(int id) { using (AmazonspiderDbContext context = new AmazonspiderDbContext()) { var product = context.Products.Where(q => q.Id == id).FirstOrDefault(); if (product != null) { var images = context.ProductImages.Where(q => q.Asin == product.Asin).ToList(); foreach (var image in images) { context.ProductImages.Remove(image); } context.Products.Remove(product); try { context.SaveChanges(); } catch (Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger("testApp.Logging");//获取一个日志记录器 log.Error("移除商品异常--", ex); } } } }
public static ProductImage AddOrUpdate(ProductImage productImage) { using (AmazonspiderDbContext context = new AmazonspiderDbContext()) { if (productImage.Id > 0) { var p = context.ProductImages.Where(q => q.Id == productImage.Id).FirstOrDefault(); if (p != null) { p.Status = productImage.Status; } } else { productImage = context.ProductImages.Add(productImage); } try { lock (AmazonspiderDbContext.sqlLiteLock) { context.SaveChanges(); return(productImage); } } catch (Exception ex) { productImage.Id = -1; return(productImage); } finally { } } }
public static void Delete(TaskSchedule taskSchedule) { using (AmazonspiderDbContext context = new AmazonspiderDbContext()) { try { taskSchedule = context.TaskSchedules.Where(q => q.Id == taskSchedule.Id).FirstOrDefault(); if (taskSchedule != null) { context.TaskSchedules.Remove(taskSchedule); context.SaveChanges(); } } catch (Exception ex) { } } }
public static void AddOrUpdate(TaskSchedule taskSchedule) { using (AmazonspiderDbContext context = new AmazonspiderDbContext()) { try { if (taskSchedule.Id > 0) { var t = context.TaskSchedules.Where(q => q.Id == taskSchedule.Id).FirstOrDefault(); if (t != null) { t.PlayerAccountId = taskSchedule.PlayerAccountId; t.PlayerStep = taskSchedule.PlayerStep; t.PlayerType = taskSchedule.PlayerType; t.RunDateTime = taskSchedule.RunDateTime; } else { if (taskSchedule.PlayerAccountId > 0) { taskSchedule.Id = 0; context.TaskSchedules.Add(taskSchedule); } } } else { if (taskSchedule.PlayerAccountId > 0) { context.TaskSchedules.Add(taskSchedule); } } lock (AmazonspiderDbContext.sqlLiteLock) { context.SaveChanges(); } } catch (Exception ex) { } } }
public static TaskSchedule Get() { lock (lockTaskSchedule) { using (AmazonspiderDbContext context = new AmazonspiderDbContext()) { var time = DateTime.Now.GetTimestamp(); var TaskSchedule = context.TaskSchedules.Where(q => q.RunDateTime <= time && q.PlayerAccountId > 0).OrderBy(q => q.PlayerStep).FirstOrDefault(); if (TaskSchedule != null) { context.TaskSchedules.Remove(TaskSchedule); lock (AmazonspiderDbContext.sqlLiteLock) { context.SaveChanges(); } } return(TaskSchedule); } } }
public static Product AddOrUpdate(Product product) { using (AmazonspiderDbContext context = new AmazonspiderDbContext()) { lock (AmazonspiderDbContext.sqlLiteLock) { var p = context.Products.Where(q => q.Asin == product.Asin).FirstOrDefault(); if (p != null) { if (product.Id > -2) { p.Price = product.Price; p.Status = product.Status; p.Title = product.Title; p.Desc = product.Desc; } } else { product = context.Products.Add(product); } try { context.SaveChanges(); return(product); } catch (Exception ex) { product.Id = -1; return(product); } finally { } } } }