/// <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)); }