コード例 #1
0
 public void Delete(int categoryId)
 {
     Trace.Assert(Context.PersonId.HasValue && Context.SchoolLocalId.HasValue);
     DoUpdate(u =>
     {
         var da       = new LPGalleryCategoryDataAccess(u);
         var category = da.GetById(categoryId);
         EnsureInDeletePermission(category);
         da.Delete(categoryId);
     });
 }
コード例 #2
0
 public LPGalleryCategory Edit(int categoryId, string name)
 {
     ValidateParams(name);
     using (var uow = Update())
     {
         var da = new LPGalleryCategoryDataAccess(uow);
         if (da.Exists(name, categoryId))
         {
             throw new ChalkableException("Category with such name already exists");
         }
         var category = da.GetById(categoryId);
         EnsureModifyPermission(category);
         category.Name = name;
         da.Update(category);
         uow.Commit();
         return(category);
     }
 }
コード例 #3
0
        public LPGalleryCategory Add(string name)
        {
            Trace.Assert(Context.PersonId.HasValue);
            ValidateParams(name);
            BaseSecurity.EnsureAdminOrTeacher(Context);
            var res = new LPGalleryCategory {
                Name = name, OwnerRef = Context.PersonId.Value
            };

            using (var u = Update())
            {
                var da = new LPGalleryCategoryDataAccess(u);
                if (da.Exists(name, null))
                {
                    throw new ChalkableException("Category with such name already exists");
                }
                da.Insert(res);
                res = da.GetAll().Last();
                u.Commit();
                return(res);
            }
        }