public IList <AnnouncementAttachment> GetAnnouncementAttachments(int announcementId, int start = 0, int count = int.MaxValue, bool needsAllAttachments = true) { Trace.Assert(Context.PersonId.HasValue); Trace.Assert(Context.SchoolLocalId.HasValue); using (var uow = Read()) { var da = new AnnouncementAttachmentDataAccess(uow); return(da.GetPaginatedList(announcementId, Context.PersonId.Value, Context.Role.Id, start, count, needsAllAttachments).ToList()); } }
public void Delete(int announcementAttachmentId) { Trace.Assert(Context.SchoolLocalId.HasValue); using (var uow = Update()) { var da = new AnnouncementAttachmentDataAccess(uow); var annAtt = GetAnnouncementAttachmentById(announcementAttachmentId); if (!CanDeleteAttachment(annAtt)) { throw new ChalkableSecurityException(); } da.Delete(annAtt.Id); uow.Commit(); } }
/// <summary> /// </summary> /// <returns>Source annAttahcment and new annAttachment</returns> public static IList <Pair <AnnouncementAttachment, AnnouncementAttachment> > CopyAnnouncementAttachments(IDictionary <int, int> fromToAnnouncementIds, IList <int> attachmentsOwners, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator) { Trace.Assert(serviceLocator.Context.PersonId.HasValue); //var attachmentDA = new AttachmentDataAccess(unitOfWork); var annoncementAttachmentDA = new AnnouncementAttachmentDataAccess(unitOfWork); var annAttachmentsToCopy = annoncementAttachmentDA.GetByAnnouncementIds(fromToAnnouncementIds.Select(x => x.Key).ToList(), attachmentsOwners); var fromToAnnAttachments = new List <Pair <AnnouncementAttachment, AnnouncementAttachment> >(); foreach (var announcementPair in fromToAnnouncementIds) { var announcementAttachmentsToCopy = annAttachmentsToCopy.Where(x => x.AnnouncementRef == announcementPair.Key).ToList(); foreach (var annAttachmentToCopy in announcementAttachmentsToCopy) { //var newAttachment = new Attachment //{ // Name = annAttachmentToCopy.Attachment.Name, // PersonRef = serviceLocator.Context.PersonId.Value, // Uuid = null, // UploadedDate = serviceLocator.Context.NowSchoolTime, // LastAttachedDate = serviceLocator.Context.NowSchoolTime, //}; //newAttachment.Id = attachmentDA.InsertWithEntityId(newAttachment); var newAnnAttachment = new AnnouncementAttachment { AnnouncementRef = announcementPair.Value, AttachedDate = annAttachmentToCopy.AttachedDate, Order = annAttachmentToCopy.Order, AttachmentRef = annAttachmentToCopy.AttachmentRef, Attachment = annAttachmentToCopy.Attachment }; fromToAnnAttachments.Add(new Pair <AnnouncementAttachment, AnnouncementAttachment>(annAttachmentToCopy, newAnnAttachment)); } } annoncementAttachmentDA.Insert(fromToAnnAttachments.Select(x => x.Second).ToList()); return(fromToAnnAttachments); }
public static IList <AnnouncementAttachment> CopyAnnouncementAttachments(int fromAnnouncementId, IList <int> attachmentsOwners, IList <int> toAnnouncemenIds, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator) { Trace.Assert(serviceLocator.Context.PersonId.HasValue); var da = new AnnouncementAttachmentDataAccess(unitOfWork); var annAttachmentsForCopying = attachmentsOwners.Count == 0 ? da.GetLastAttachments(fromAnnouncementId).ToList() : da.GetLastAttachments(fromAnnouncementId).Where(x => attachmentsOwners.Contains(x.Attachment.PersonRef)).ToList(); var annAtts = new List <AnnouncementAttachment>(); foreach (var annAttForCopy in annAttachmentsForCopying) { foreach (var toAnnouncemenId in toAnnouncemenIds) { //var attForCopy = annAttForCopy.Attachment; //var content = serviceLocator.AttachementService.GetAttachmentContent(attForCopy).Content; //if (content != null) //{ // var att = AttachmentService.Upload(attForCopy.Name, content, attForCopy.IsStiAttachment, unitOfWork, serviceLocator, connectorLocator); // var annAtt = new AnnouncementAttachment // { // AnnouncementRef = toAnnouncemenId, // AttachedDate = annAttForCopy.AttachedDate, // Order = annAttForCopy.Order, // AttachmentRef = att.Id, // Attachment = att // }; // annAtts.Add(annAtt); //} var annAtt = new AnnouncementAttachment { AnnouncementRef = toAnnouncemenId, AttachedDate = annAttForCopy.AttachedDate, Order = annAttForCopy.Order, AttachmentRef = annAttForCopy.AttachmentRef, Attachment = annAttForCopy.Attachment }; annAtts.Add(annAtt); } } da.Insert(annAtts); return(da.GetLastAttachments(toAnnouncemenIds, annAtts.Count)); }
public AnnouncementAttachment UploadAttachment(int announcementId, AnnouncementTypeEnum type, byte[] content, string name) { 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 uow = Update()) { var att = AttachmentService.Upload(name, content, false, uow, ServiceLocator, ConnectorLocator); var annAtt = new AnnouncementAttachment { AnnouncementRef = annDetails.Id, AttachedDate = Context.NowSchoolTime, Order = ServiceLocator.GetAnnouncementService(type).GetNewAnnouncementItemOrder(annDetails), AttachmentRef = att.Id, }; var da = new AnnouncementAttachmentDataAccess(uow); var attId = da.InsertWithEntityId(annAtt); uow.Commit(); bool notifyUsers = !annDetails.IsOwner || (annDetails.ClassAnnouncementData != null && annDetails.ClassAnnouncementData.VisibleForStudent) || (annDetails.LessonPlanData != null && annDetails.LessonPlanData.VisibleForStudent) || annDetails.AdminAnnouncementData != null; if (notifyUsers) { NotifyUsers(annDetails, type); } return(da.GetById(attId, Context.PersonId.Value, Context.RoleId, true)); } }