示例#1
0
 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);
             }
         }
     }
 }
示例#2
0
 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
         {
         }
     }
 }
示例#3
0
 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)
         {
         }
     }
 }
示例#4
0
 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)
         {
         }
     }
 }
示例#5
0
        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);
                }
            }
        }
示例#6
0
 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
             {
             }
         }
     }
 }