private void EnsureModifyPermission(LPGalleryCategory category)
 {
     if (category.OwnerRef != Context.PersonId)
     {
         throw new ChalkableSecurityException("Only owner can modify category");
     }
 }
Example #2
0
 private void EnsureInDeletePermission(LPGalleryCategory category)
 {
     EnsureModifyPermission(category);
     if (category.LessonPlansCount > 0)
     {
         throw new ChalkableException("Current GalleryCategory has lessonPlanTemplates. You can't delete such category");
     }
 }
 public static LPGalleryCategoryViewData Create(LPGalleryCategory category)
 {
     return(new LPGalleryCategoryViewData
     {
         Id = category.Id,
         Name = category.Name,
         OwnerId = category.OwnerRef,
         LessonPlansCount = category.LessonPlansCount
     });
 }
Example #4
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);
            }
        }