public void UpdateAnnouncementApplicationMeta(int announcementApplicationId, AnnouncementTypeEnum announcementType, string text, string imageUrl, string description)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);
            using (var uow = Update())
            {
                var da  = new AnnouncementApplicationDataAccess(uow);
                var aa  = da.GetById(announcementApplicationId);
                var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(aa.AnnouncementRef);
                if (!ann.IsOwner && Context.Role != CoreRoles.DISTRICT_ADMIN_ROLE)
                {
                    throw new ChalkableSecurityException(ChlkResources.ERR_SECURITY_EXCEPTION);
                }
                aa.Text = text;

                if (string.IsNullOrWhiteSpace(imageUrl) || !Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute))
                {
                    imageUrl = null;
                }

                aa.ImageUrl    = imageUrl;
                aa.Description = description;
                da.Update(aa);
                uow.Commit();
            }
        }
        public AnnouncementApplication AddToAnnouncement(int announcementId, AnnouncementTypeEnum type, Guid applicationId)
        {
            var app = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationById(applicationId);

            EnsureApplicationPermission(app.Id);

            using (var uow = Update())
            {
                var ann = ServiceLocator.GetAnnouncementService(type).GetAnnouncementDetails(announcementId);
                if (!ApplicationSecurity.CanAddToAnnouncement(app, ann, Context))
                {
                    throw new ChalkableSecurityException();
                }
                var aa = new AnnouncementApplication
                {
                    AnnouncementRef = announcementId,
                    ApplicationRef  = applicationId,
                    Active          = false,
                    Order           = ServiceLocator.GetAnnouncementService(type).GetNewAnnouncementItemOrder(ann)
                };
                var da = new AnnouncementApplicationDataAccess(uow);
                da.Insert(aa);
                uow.Commit();
                aa = da.GetAll(new AndQueryCondition
                {
                    { nameof(AnnouncementApplication.AnnouncementRef), announcementId },
                    { nameof(AnnouncementApplication.ApplicationRef), applicationId },
                    { nameof(AnnouncementApplication.Active), false }
                }).OrderByDescending(x => x.Id).First();
                return(aa);
            }
        }
 public IList <AnnouncementApplication> GetAnnouncementApplicationsByAnnIds(IList <int> announcementIds, bool onlyActive = false)
 {
     using (var uow = Read())
     {
         var res = new AnnouncementApplicationDataAccess(uow).GetAnnouncementApplicationsbyAnnIds(announcementIds);
         if (onlyActive)
         {
             res = res.Where(x => x.Active).ToList();
         }
         return(res);
     }
 }
 public IList <AnnouncementApplication> GetAnnouncementApplicationsByAnnId(int announcementId, bool onlyActive = false)
 {
     //TODO: thing about security
     using (var uow = Read())
     {
         var da = new AnnouncementApplicationDataAccess(uow);
         var ps = new AndQueryCondition {
             { nameof(AnnouncementApplication.AnnouncementRef), announcementId }
         };
         if (onlyActive)
         {
             ps.Add(nameof(AnnouncementApplication.Active), true);
         }
         return(da.GetAll(ps));
     }
 }
        public static IList <AnnouncementApplication> CopyAnnApplications(IList <AnnouncementApplication> annAppsForCopying, IList <int> toAnnouncementIds, UnitOfWork unitOfWork)
        {
            var da = new AnnouncementApplicationDataAccess(unitOfWork);

            foreach (var toAnnouncementId in toAnnouncementIds)
            {
                var res = annAppsForCopying.Select(aa => new AnnouncementApplication
                {
                    ApplicationRef  = aa.ApplicationRef,
                    Active          = aa.Active,
                    Order           = aa.Order,
                    AnnouncementRef = toAnnouncementId,
                }).ToList();
                da.Insert(res);
            }
            return(da.GetAnnouncementApplicationsbyAnnIds(toAnnouncementIds));
        }
        public void AttachAppToAnnouncement(int announcementAppId, AnnouncementTypeEnum announcementType)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);
            using (var uow = Update())
            {
                var da = new AnnouncementApplicationDataAccess(uow);
                var aa = da.GetById(announcementAppId);

                var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(aa.AnnouncementRef);
                if (!ann.IsOwner && Context.Role != CoreRoles.DISTRICT_ADMIN_ROLE)
                {
                    throw new ChalkableSecurityException(ChlkResources.ERR_SECURITY_EXCEPTION);
                }
                aa.Active = true;
                da.Update(aa);
                uow.Commit();
            }
        }
Пример #7
0
        private void EnsureAdminAnnouncementDelete(Announcement announcement, UnitOfWork unitOfWork)
        {
            if (!AnnouncementSecurity.CanDeleteAnnouncement(announcement, Context))
            {
                throw new ChalkableSecurityException();
            }
            var assessmentId       = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetAssessmentId();
            var assessmentAttached = new AnnouncementApplicationDataAccess(unitOfWork).Exists(new AndQueryCondition
            {
                { nameof(AnnouncementApplication.AnnouncementRef), announcement.Id },
                { nameof(AnnouncementApplication.ApplicationRef), assessmentId },
                { nameof(AnnouncementApplication.Active), true }
            });

            if (assessmentAttached)
            {
                throw new AnnouncementDeleteFailedException(ChlkResources.ERR_CANT_DELETE_ITEM_WITH_ASSESSMENT, ChlkResources.ERR_TITLE_ATTACHED_ASSESSMENT);
            }
        }
        public Announcement RemoveFromAnnouncement(int announcementAppId, AnnouncementTypeEnum type)
        {
            try
            {
                using (var uow = Update())
                {
                    var da  = new AnnouncementApplicationDataAccess(uow);
                    var aa  = da.GetById(announcementAppId);
                    var res = ServiceLocator.GetAnnouncementService(type).GetAnnouncementById(aa.AnnouncementRef);
                    if (!res.IsOwner && Context.Role != CoreRoles.DISTRICT_ADMIN_ROLE)
                    {
                        throw new ChalkableSecurityException(ChlkResources.ERR_SECURITY_EXCEPTION);
                    }

                    da.Delete(announcementAppId);
                    uow.Commit();
                    return(res);
                }
            }
            catch
            {
                throw new ChalkableException(string.Format(ChlkResources.ERR_CANT_DELETE_ANNOUNCEMENT_APPLICATION, announcementAppId));
            }
        }