예제 #1
0
 public static bool AddRecommendation(RECOMMENDATION reco)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Set<RECOMMENDATION>().Add(reco);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #2
0
 public static bool AddCategory(CATEGORY category)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Set<CATEGORY>().Add(category);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #3
0
 /// <summary>
 /// 创建新的ManagerType,注意ManagerType和Type在当前语义下表示意义相同,均表示Manager的类型
 /// </summary>
 /// <param name="type">需要创建的Type,需要在函数外部创建实例,并且为DESCRIPTION属性赋值</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool AddManagerType(TYPE type)
 {
     int count = 0;
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.TYPEs.Add(type);
             count = ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return count == 1;
 }
예제 #4
0
 /// <summary>
 /// 创建新的Permission
 /// </summary>
 /// <param name="permission">需要创建的Manager,需要在函数外部创建实例,并且为NAME和TYPE属性赋值</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool AddPermission(PERMISSION permission)
 {
     int count = 0;
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.PERMISSIONs.Add(permission);
             count = ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return count == 1;
 }
예제 #5
0
        public static bool AddCourseToRecommendation(COURSE course, RECOMMENDATION reco)
        {
            using (CloudEDUEntities ctx = new CloudEDUEntities())
            {
                try
                {
                    var rc = ctx.RECOMMENDATIONs.Include("COURSEs").Where(r => r.ID == reco.ID).FirstOrDefault();
                    var cs = ctx.COURSEs.Where(c => c.ID == course.ID).FirstOrDefault();
                    rc.COURSEs.Add(cs);
                    ctx.Entry(rc).State = System.Data.EntityState.Modified;
                    ctx.SaveChanges();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                    return false;
                }

            }
            return true;
        }
예제 #6
0
 /// <summary>
 /// 移除TYPE。如果有Manager与该TYPE相关联,则该Manager的MNGR_TYPE将会为NULL
 /// </summary>
 /// <param name="type_id">被删除的TYPE的id</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool RemoveManagerType(int type_id)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             var type = ctx.TYPEs.Where(m => m.ID == type_id).FirstOrDefault<TYPE>();
             ctx.Set<TYPE>().Remove(type);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
     //throw new Exception("Not Support Yet");
 }
예제 #7
0
 public static bool RemoveManager(int manager_id)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             var manager = ctx.MANAGERs.Where(m => m.ID == manager_id).FirstOrDefault<MANAGER>();
             ctx.Set<MANAGER>().Remove(manager);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #8
0
 private static bool AddResourcesToLesson(RESOURCE[] res, LESSON lesson)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         var ls = ctx.LESSONs.Include("RESOURCEs").Where(l => l.ID == lesson.ID).FirstOrDefault();
         foreach (RESOURCE rs in res)
             ls.RESOURCEs.Add(rs);
         ctx.Entry(ls).State = System.Data.EntityState.Modified;
         ctx.SaveChanges();
     }
     return true;
 }
예제 #9
0
 /// <summary>
 /// 用于更改TYPE的一般信息,包括DESCRIPTION
 /// </summary>
 /// <param name="type">更改后的TYPE的实例</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool UpdateManagerType(TYPE type)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Entry(type).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #10
0
 public static bool ToggleNoteSharability(NOTE note)
 {
     note.SHARE = !note.SHARE;
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Set<NOTE>().Attach(note);
             ctx.Entry(note).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #11
0
 public static bool RemoveResource(RESOURCE resource)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Set<RESOURCE>().Attach(resource);
             ctx.Set<RESOURCE>().Remove(resource);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #12
0
 public static bool RemoveLesson(LESSON lesson)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Set<LESSON>().Attach(lesson);
             ctx.Set<LESSON>().Remove(lesson);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #13
0
 public static bool RemoveDocument(DOCUMENT document)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Set<DOCUMENT>().Attach(document);
             ctx.Set<DOCUMENT>().Remove(document);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #14
0
 public static bool RemoveCourseFromRecommendation(COURSE course, RECOMMENDATION reco)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.RECOMMENDATIONs.Attach(reco);
             ctx.COURSEs.Attach(course);
             reco.COURSEs.Remove(course);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #15
0
 public static bool RemovePermission(int permission_id)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             var permission = ctx.PERMISSIONs.Where(m => m.ID == permission_id).FirstOrDefault<PERMISSION>();
             ctx.Set<PERMISSION>().Remove(permission);
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #16
0
 /// <summary>
 /// 回收授予某Manager的权限
 /// </summary>
 /// <param name="manager_id">被回收的Manager的ID</param>
 /// <param name="permission_id">被回收的Permission的ID</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool RevokePermissionFromManager(int manager_id, int permission_id)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             var manager = ctx.MANAGERs.Include("PERMISSIONs").Where(mngr => mngr.ID == manager_id).FirstOrDefault<MANAGER>();
             var perm = ctx.PERMISSIONs.Where(p => p.ID == permission_id).FirstOrDefault<PERMISSION>();
             //System.Diagnostics.Debug.WriteLine(ctx.Entry(manager).State);
             //System.Diagnostics.Debug.WriteLine(ctx.Entry(perm).State);
             manager.PERMISSIONs.Remove(perm);
             ctx.Entry(manager).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #17
0
 /// <summary>
 /// 用于更新课程的状态,状态包括Pending、OK、Cancel三项
 /// </summary>
 /// <param name="course_id">课程的ID</param>
 /// <param name="state">课程的状态,类型为枚举CourseStatus</param>
 /// <returns>true表示成功,false表示失败</returns>
 public static bool UpdateCourseStatus(int course_id, CourseStatus state)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             COURSE course = ctx.COURSEs.Where(c => c.ID == course_id).FirstOrDefault();
             course.COURSE_STATUS = state.ToString();
             ctx.Entry(course).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #18
0
 /// <summary>
 /// 用于更改Permission的一般信息,包括NAME和TYPE
 /// </summary>
 /// <param name="permission">更改后的Permission的实例</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool UpdatePermission(PERMISSION permission)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Entry(permission).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #19
0
 public static bool UpdateRecommendation(RECOMMENDATION reco)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             ctx.Entry(reco).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }
예제 #20
0
 /// <summary>
 /// 用于更改Manager的Type
 /// </summary>
 /// <param name="manager">需要更改的Manager的实例</param>
 /// <param name="type">需要改为的Type的ID</param>
 /// <returns>true表示成功创建,false表示失败</returns>
 public static bool ChangeManagerManagerType(MANAGER manager, int type)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             manager.MNGR_TYPE = type;
             ctx.Entry(manager).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
     //throw new Exception("Not Support Yet");
 }
예제 #21
0
 private static bool AddLessonsToCourse(LESSON[] lessons, COURSE course)
 {
     using (CloudEDUEntities ctx = new CloudEDUEntities())
     {
         try
         {
             var cs = ctx.COURSEs.Include("LESSONs").Where(c => c.ID == course.ID).FirstOrDefault();
             foreach (LESSON ls in lessons)
                 cs.LESSONs.Add(ls);
             ctx.Entry(cs).State = System.Data.EntityState.Modified;
             ctx.SaveChanges();
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e.ToString());
             return false;
         }
     }
     return true;
 }