예제 #1
0
 public SubjectCategoryObject SaveSubjectCategory(SubjectCategoryObject subjectCategory)
 {
     if (subjectCategory.SubjectCategoryId > 0) // Update
     {
         string sql = @"
             UPDATE  lu_SubjectCategory
             SET     CategoryId = @CategoryId,
                     Subject = @Subject,
                     Active = @Active
             WHERE   SubjectCategoryId = @SubjectCategoryId";
         Config.Conn.Execute(sql, subjectCategory);
     }
     else
     {
         string sql = @"
             INSERT INTO lu_SubjectCategory (
                 CategoryId,
                 Subject,
                 Active
             )
             VALUES (
                 @CategoryId,
                 @Subject,
                 @Active
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         subjectCategory.SubjectCategoryId = Config.Conn.Query <int>(sql, subjectCategory).Single();
     }
     return(subjectCategory);
 }
예제 #2
0
 public bool DeleteSubjectCategory(SubjectCategoryObject subjectCategory)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM lu_SubjectCategory WHERE SubjectCategoryId = @SubjectCategoryId", subjectCategory);
     }
     catch { return(false); }
     return(true);
 }
예제 #3
0
        public static List <SubjectCategoryObject> GetSubjectCategories(bool enabledOnly = false, int?requiredId = null)
        {
            var cache = HttpContext.Current.Cache;
            List <SubjectCategoryObject> data = (List <SubjectCategoryObject>)cache[SubjectCategoryKey];

            if (data == null)
            {
                data = SubjectCategoryObject.GetSubjectCategories();
                cache.Insert(SubjectCategoryKey, data, null, DateTime.Now.AddMinutes(60), Cache.NoSlidingExpiration);
            }
            return(data.Where(n => (!enabledOnly || n.Active || (requiredId.HasValue && n.SubjectCategoryId == requiredId.Value))).ToList());
        }