Пример #1
0
        public ActionResult UploadAnnouncementAttachment(int announcementId, int announcementType)
        {
            try
            {
                EnsureAnnouncementExsists(announcementId, announcementType);

                byte[] bin;
                string name;
                if (!GetFileFromRequest(out bin, out name))
                {
                    return(Json(new ChalkableException(ChlkResources.ERR_FILE_REQUIRED)));
                }
                var attachment = SchoolLocator.AnnouncementAttachmentService.UploadAttachment(announcementId, (AnnouncementTypeEnum)announcementType, bin, name);
                var res        = SchoolLocator.AnnouncementAttachmentService.TransformToAttachmentsInfo(new List <AnnouncementAttachment> {
                    attachment
                }, new List <int> {
                    Context.PersonId.Value
                });
                return(Json(AnnouncementAttachmentViewData.Create(res[0], true), HTML_CONTENT_TYPE, 6));
            }
            catch (Exception exception)
            {
                return(HandleAttachmentException(exception));
            }
        }
Пример #2
0
        public ActionResult GetAttachments(int announcementId, int?announcementType, int?start, int?count)
        {
            EnsureAnnouncementExsists(announcementId, announcementType);

            var announcementAttachments = SchoolLocator.AnnouncementAttachmentService.GetAnnouncementAttachments(announcementId, start ?? 0, count ?? 10, false);
            var attachmentsInfo         = SchoolLocator.AnnouncementAttachmentService.TransformToAttachmentsInfo(announcementAttachments, null);
            var res = AnnouncementAttachmentViewData.Create(attachmentsInfo, SchoolLocator.Context.PersonId ?? 0);

            return(Json(res));
        }
        public static AnnouncementDetailedViewData Create(AnnouncementDetails announcementDetails, int currentSchoolPersonId,
                                                          IList <AnnouncementAttachmentInfo> attachmentInfos, IList <AttachmentInfo> attrAttachmentInfos, IList <ClaimInfo> claims)
        {
            var res = Create(announcementDetails, currentSchoolPersonId, claims);

            res.AnnouncementAttachments = AnnouncementAttachmentViewData.Create(attachmentInfos, currentSchoolPersonId);

            if (announcementDetails.AnnouncementAttributes != null)
            {
                res.AnnouncementAttributes = AnnouncementAssignedAttributeViewData.Create(announcementDetails.AnnouncementAttributes, attrAttachmentInfos);
            }
            return(res);
        }
Пример #4
0
        public ActionResult UploadAnnouncementAttachment(int announcementId, int announcementType, string fileName)
        {
            EnsureAnnouncementExsists(announcementId, announcementType);

            var length = Request.InputStream.Length;

            if (length == 0)
            {
                return(Json(new ChalkableException(ChlkResources.ERR_FILE_REQUIRED)));
            }

            var bin = new byte[length];

            Request.InputStream.Read(bin, 0, (int)length);

            var attachment = SchoolLocator.AnnouncementAttachmentService.UploadAttachment(announcementId, (AnnouncementTypeEnum)announcementType, bin, fileName);
            var res        = SchoolLocator.AnnouncementAttachmentService.TransformToAttachmentsInfo(new List <AnnouncementAttachment> {
                attachment
            }, new List <int> {
                Context.PersonId.Value
            });

            return(Json(AnnouncementAttachmentViewData.Create(res[0], true)));
        }