Exemple #1
0
        public Announcement Add(int announcementId, AnnouncementTypeEnum type, int attachmentId)
        {
            var annDetails = ServiceLocator.GetAnnouncementService(type).GetAnnouncementDetails(announcementId);

            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);
            if (!CanAttach(annDetails))
            {
                throw new ChalkableSecurityException();
            }

            using (var u = Update())
            {
                var attDa = new AttachmentDataAccess(u);
                var att   = attDa.GetById(attachmentId);
                if (att.PersonRef != Context.PersonId)
                {
                    throw new ChalkableSecurityException();
                }

                var annAtt = new AnnouncementAttachment
                {
                    AnnouncementRef = annDetails.Id,
                    AttachedDate    = Context.NowSchoolTime,
                    Order           = ServiceLocator.GetAnnouncementService(type).GetNewAnnouncementItemOrder(annDetails),
                    AttachmentRef   = attachmentId
                };
                new AnnouncementAttachmentDataAccess(u).Insert(annAtt);
                att.LastAttachedDate = annAtt.AttachedDate;
                attDa.Update(att);
                u.Commit();
                NotifyUsers(annDetails, type);
            }
            return(annDetails);
        }
Exemple #2
0
        public AnnouncementAssignedAttribute AddAttachment(AnnouncementTypeEnum announcementType, int announcementId, int assignedAttributeId, int attachmentId)
        {
            Trace.Assert(Context.PersonId.HasValue);
            var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(announcementId);

            if (!CanAttach(ann))
            {
                throw new ChalkableSecurityException();
            }

            using (var uow = Update())
            {
                var da        = new AnnouncementAssignedAttributeDataAccess(uow);
                var attribute = da.GetById(assignedAttributeId);
                if (attribute.AttachmentRef > 0)
                {
                    throw new ChalkableSisException("You can't attach more than one file to an attribute");
                }

                var attDa      = new AttachmentDataAccess(uow);
                var attachment = attDa.GetById(attachmentId);
                if (attachment.PersonRef != Context.PersonId)
                {
                    throw new ChalkableSecurityException();
                }

                attribute.AttachmentRef = attachment.Id;
                attribute.Attachment    = attachment;
                da.Update(attribute);

                if (announcementType == AnnouncementTypeEnum.Class)
                {
                    if (!attachment.SisAttachmentId.HasValue)
                    {
                        var attContent = ServiceLocator.AttachementService.GetAttachmentContent(attachment);
                        var stiAtt     = ConnectorLocator.AttachmentConnector.UploadAttachment(attachment.Name, attContent.Content).Last();
                        MapperFactory.GetMapper <Attachment, StiAttachment>().Map(attachment, stiAtt);
                        attDa.Update(attachment);
                    }

                    if (attribute.SisActivityAssignedAttributeId.HasValue)
                    {
                        var stiAttribute = ConnectorLocator.ActivityAssignedAttributeConnector.GetAttribute(attribute.SisActivityId.Value, attribute.SisActivityAssignedAttributeId.Value);
                        MapperFactory.GetMapper <ActivityAssignedAttribute, AnnouncementAssignedAttribute>().Map(stiAttribute, attribute);
                        ConnectorLocator.ActivityAssignedAttributeConnector.Update(stiAttribute.ActivityId, stiAttribute.Id, stiAttribute);
                    }
                }
                uow.Commit();
                return(attribute);
            }
        }
Exemple #3
0
 public void Delete(int attachmentId)
 {
     DoUpdate(u =>
     {
         var da  = new AttachmentDataAccess(u);
         var att = da.GetById(attachmentId);
         if (att.PersonRef != Context.PersonId)
         {
             throw new ChalkableSecurityException();
         }
         da.Delete(attachmentId);
         if (att.SisAttachmentId.HasValue)
         {
             ConnectorLocator.AttachmentConnector.DeleteAttachment(att.SisAttachmentId.Value);
         }
         else
         {
             ServiceLocator.StorageBlobService.DeleteBlob(ATTACHMENT_CONTAINER_ADDRESS, att.RelativeBlobAddress);
         }
     });
 }