示例#1
0
        public AnnouncementAssignedAttribute RemoveAttachment(int announcementAssignedAttributeId)
        {
            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);

            using (var uow = Update())
            {
                var da        = new AnnouncementAssignedAttributeDataAccess(uow);
                var attribute = da.GetById(announcementAssignedAttributeId);
                if (!attribute.AttachmentRef.HasValue)
                {
                    throw new ChalkableException("Attribute has no attachments for remove.");
                }
                if (attribute.IsStiAttribute)
                {
                    var activityAssignedAttribute = ConnectorLocator.ActivityAssignedAttributeConnector.GetAttribute(attribute.SisActivityId.Value, attribute.SisActivityAssignedAttributeId.Value);
                    activityAssignedAttribute.Attachment = null;
                    ConnectorLocator.ActivityAssignedAttributeConnector.Update(attribute.SisActivityId.Value, attribute.SisActivityAssignedAttributeId.Value, activityAssignedAttribute);
                }
                attribute.AttachmentRef = null;
                da.Update(attribute);
                uow.Commit();
                return(attribute);
            }
        }
示例#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);
            }
        }
示例#3
0
 public void Delete(int assignedAttributeId)
 {
     BaseSecurity.EnsureAdminOrTeacher(Context);
     Trace.Assert(Context.PersonId.HasValue);
     Trace.Assert(Context.SchoolLocalId.HasValue);
     DoUpdate(u =>
     {
         var da        = new AnnouncementAssignedAttributeDataAccess(u);
         var attribute = da.GetById(assignedAttributeId);
         if (attribute.SisActivityId.HasValue && attribute.SisActivityAssignedAttributeId.HasValue)
         {
             ConnectorLocator.ActivityAssignedAttributeConnector.Delete(attribute.SisActivityId.Value, attribute.SisActivityAssignedAttributeId.Value);
         }
         da.Delete(assignedAttributeId);
     });
 }
示例#4
0
        public AnnouncementAssignedAttribute Add(AnnouncementTypeEnum announcementType, int announcementId, int attributeTypeId)
        {
            var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(announcementId);

            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);

            var attributeType = ServiceLocator.AnnouncementAttributeService.GetAttributeById(attributeTypeId, true);


            using (var uow = Update())
            {
                if (!CanAttach(ann))
                {
                    throw new ChalkableSecurityException();
                }

                var annAttribute = new AnnouncementAssignedAttribute
                {
                    AnnouncementRef    = ann.Id,
                    AttributeTypeId    = attributeType.Id,
                    Text               = "",
                    VisibleForStudents = false,
                    Name               = attributeType.Name
                };

                if (announcementType == AnnouncementTypeEnum.Class)
                {
                    var announcement = ServiceLocator.ClassAnnouncementService.GetClassAnnouncemenById(announcementId);
                    if (announcement.SisActivityId.HasValue)
                    {
                        var activityAssignedAttr = new ActivityAssignedAttribute();
                        MapperFactory.GetMapper <ActivityAssignedAttribute, AnnouncementAssignedAttribute>().Map(activityAssignedAttr, annAttribute);
                        activityAssignedAttr.Text = " ";
                        activityAssignedAttr      = ConnectorLocator.ActivityAssignedAttributeConnector.CreateActivityAttribute(announcement.SisActivityId.Value, activityAssignedAttr);
                        MapperFactory.GetMapper <AnnouncementAssignedAttribute, ActivityAssignedAttribute>().Map(annAttribute, activityAssignedAttr);
                        annAttribute.Name = attributeType.Name;//activity attr returns null name
                    }
                }

                var da = new AnnouncementAssignedAttributeDataAccess(uow);
                var id = da.InsertWithEntityId(annAttribute);
                uow.Commit();
                return(da.GetById(id));
            }
        }
示例#5
0
        public AnnouncementAssignedAttribute UploadAttachment(AnnouncementTypeEnum announcementType, int announcementId, int assignedAttributeId, byte[] bin, string name)
        {
            Trace.Assert(Context.PersonId.HasValue && Context.SchoolLocalId.HasValue);
            var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(announcementId);

            using (var uow = Update())
            {
                var da = new AnnouncementAssignedAttributeDataAccess(uow);
                var assignedAttribute = da.GetById(assignedAttributeId);
                if (!CanAttach(ann))
                {
                    throw new ChalkableSecurityException();
                }

                if (assignedAttribute.AttachmentRef > 0)
                {
                    throw new ChalkableSisException("You can't attach more than one file to an attribute");
                }

                var isStiAttribute = assignedAttribute.IsStiAttribute || announcementType == AnnouncementTypeEnum.Class;
                var attachment     = AttachmentService.Upload(name, bin, isStiAttribute, uow, ServiceLocator, ConnectorLocator);
                assignedAttribute.AttachmentRef = attachment.Id;
                assignedAttribute.Attachment    = attachment;
                da.Update(assignedAttribute);

                if (assignedAttribute.IsStiAttribute)
                {
                    var stiAttribute = ConnectorLocator.ActivityAssignedAttributeConnector.GetAttribute(
                        assignedAttribute.SisActivityId.Value,
                        assignedAttribute.SisActivityAssignedAttributeId.Value);

                    MapperFactory.GetMapper <ActivityAssignedAttribute, AnnouncementAssignedAttribute>().Map(stiAttribute, assignedAttribute);
                    ConnectorLocator.ActivityAssignedAttributeConnector.Update(stiAttribute.ActivityId, stiAttribute.Id, stiAttribute);
                }
                uow.Commit();
                return(assignedAttribute);
            }
        }