Пример #1
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)
         {
         }
     }
 }
Пример #2
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)
         {
         }
     }
 }