private void EnsureModifyPermission(LPGalleryCategory category) { if (category.OwnerRef != Context.PersonId) { throw new ChalkableSecurityException("Only owner can modify category"); } }
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 }); }
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); } }