public async Task<Cours> PrepareCoursForOpeningAsync(Cours coursToPrepare)
        {
            bool r = await GetResourcesListForThisCoursAsync(coursToPrepare);

            if (r)
            {
                foreach (ResourceList rl in (from ResourceList l
                                             in ClarolineDB.ResourceList_Table
                                             where l.Cours.Equals(coursToPrepare)
                                             select l))
                {
                    if (Enum.IsDefined(typeof(SupportedModules), rl.GetSupportedModule()))
                    {
                        await GetResourcesForThisListAsync(rl);
                    }
                }
                ClearResOfCours(coursToPrepare);

                using (ClarolineDataContext cdc = new ClarolineDataContext(ClarolineDataContext.DBConnectionString))
                {
                    coursToPrepare = (from Cours c in cdc.Cours_Table where c.Equals(coursToPrepare) select c).Single();
                    coursToPrepare.loaded = DateTime.Now;
                    int count = coursToPrepare.Resources.Count;
                    cdc.SubmitChanges();
                }
            }
            return coursToPrepare;
        }
 public void ClearCoursList()
 {
     using (ClarolineDataContext cdc = new ClarolineDataContext(ClarolineDataContext.DBConnectionString))
     {
         (from Cours c
          in cdc.Cours_Table
          select c).ToList()
          .ForEach(c =>
          {
              if (c.updated)
              {
                  c.updated = false;
              }
              else
              {
                  DeleteCours(c);
              }
          });
         cdc.SubmitChanges();
     }
 }
 public void ClearResOfCours(Cours coursToClear)
 {
     using (ClarolineDataContext cdc = new ClarolineDataContext(ClarolineDataContext.DBConnectionString))
     {
         (from ResourceModel rm
              in cdc.Resources_Table
          where rm.ResourceList.Cours.Equals(coursToClear)
          select rm).ToList()
              .ForEach(rm =>
              {
                  if (rm.updated)
                  {
                      rm.updated = false;
                  }
                  else
                  {
                      DeleteResource(rm);
                  }
              });
         cdc.SubmitChanges();
     }
 }
        public virtual void AddNotification(Notification newNot, ResourceModel attachedResource)
        {
            using (ClarolineDataContext cdc = new ClarolineDataContext(ClarolineDataContext.DBConnectionString))
            {

                Notification lastNotificationFromDB = cdc.Notifications_Table.OrderByDescending(n => n.date)
                                                                                     .FirstOrDefault(n => n.resource == newNot.resource);

                if (lastNotificationFromDB != null)
                {
                    if (lastNotificationFromDB.date.CompareTo(newNot.date) >= 0)
                    {
                        return;
                    }
                }

                newNot.resource = cdc.Resources_Table.Single(r => r.Id == attachedResource.Id);
                cdc.Notifications_Table.InsertOnSubmit(newNot);
                cdc.SubmitChanges();
            }
        }