Ejemplo n.º 1
0
 public static List <TutorialGroup> SaveTutorialGroup(TutorialGroup tutorial)
 {
     using (var entities = new QBotEntities())
     {
         try
         {
             if (tutorial.Id == 0)
             {
                 entities.TutorialGroups.Add(tutorial);
             }
             else
             {
                 TutorialGroup editTutorial = entities.TutorialGroups.Where(x => x.Id == tutorial.Id).FirstOrDefault();
                 editTutorial.Name     = tutorial.Name;
                 editTutorial.Code     = tutorial.Code;
                 editTutorial.CourseId = tutorial.CourseId;
             }
             entities.SaveChanges();
             return(entities.TutorialGroups.Where(x => x.CourseId == tutorial.CourseId).ToList());
         }
         catch (Exception e)
         {
             LogExceptions(e);
             return(null);
         }
     }
 }
Ejemplo n.º 2
0
        public static List <TutorialGroup> DeleteTutorialGroup(TutorialGroup tutorial)
        {
            using (var entities = new QBotEntities())
            {
                try
                {
                    int           CourseId = tutorial.CourseId;
                    TutorialGroup tutorialGroupToDelete = entities.TutorialGroups.Where(x => x.Id == tutorial.Id).FirstOrDefault();
                    if (tutorialGroupToDelete != null)
                    {
                        var tutorialGroupMappingsToDelete = from tutorialMapping in entities.TutorialGroupMemberships
                                                            where tutorialMapping.TutorialGroupId == tutorialGroupToDelete.Id
                                                            select tutorialMapping;
                        if (tutorialGroupMappingsToDelete != null)
                        {
                            entities.TutorialGroupMemberships.RemoveRange(tutorialGroupMappingsToDelete);
                        }

                        entities.TutorialGroups.Remove(tutorialGroupToDelete);
                        entities.SaveChanges();
                    }

                    return(entities.TutorialGroups.Where(x => x.CourseId == CourseId).ToList());
                }
                catch (Exception e)
                {
                    LogExceptions(e);
                    return(null);
                }
            }
        }