public static IList <Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute> > CopyNonStiAttributes(IDictionary <int, int> fromToAnnouncementIds, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator) { //var attachmentDA = new AttachmentDataAccess(unitOfWork); var annAssignedAttributeDA = new AnnouncementAssignedAttributeDataAccess(unitOfWork); var attributesForCopying = annAssignedAttributeDA.GetLastListByAnnIds(fromToAnnouncementIds.Select(x => x.Key).ToList(), int.MaxValue) .Where(x => !x.SisActivityAssignedAttributeId.HasValue).ToList(); var fromToAttributes = new List <Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute> >(); foreach (var announcementPair in fromToAnnouncementIds) { var assignedAttToCopy = attributesForCopying.Where(x => x.AnnouncementRef == announcementPair.Key).ToList(); foreach (var attributeToCopy in assignedAttToCopy) { var newAttribute = new AnnouncementAssignedAttribute { AnnouncementRef = announcementPair.Value, AttributeTypeId = attributeToCopy.AttributeTypeId, Name = attributeToCopy.Name, Text = attributeToCopy.Text, VisibleForStudents = attributeToCopy.VisibleForStudents, AttachmentRef = attributeToCopy.AttachmentRef, Attachment = attributeToCopy.Attachment }; //if (attributeToCopy.Attachment != null) //{ // var attachment = new Attachment // { // Name = attributeToCopy.Attachment.Name, // PersonRef = serviceLocator.Context.PersonId.Value, // Uuid = null, // UploadedDate = serviceLocator.Context.NowSchoolTime, // LastAttachedDate = serviceLocator.Context.NowSchoolTime, // }; // attachment.Id = attachmentDA.InsertWithEntityId(attachment); // newAttribute.AttachmentRef = attachment.Id; // newAttribute.Attachment = attachment; //} fromToAttributes.Add(new Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute>(attributeToCopy, newAttribute)); } } annAssignedAttributeDA.Insert(fromToAttributes.Select(x => x.Second).ToList()); return(fromToAttributes); }
public static IList <AnnouncementAssignedAttribute> CopyNonStiAttributes(int fromAnnouncementId, IList <int> toAnnouncementIds, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator) { var da = new AnnouncementAssignedAttributeDataAccess(unitOfWork); var attributesForCopying = da.GetListByAnntId(fromAnnouncementId); attributesForCopying = attributesForCopying.Where(x => !x.SisActivityAssignedAttributeId.HasValue).ToList(); var attributes = new List <AnnouncementAssignedAttribute>(); foreach (var attributeForCopying in attributesForCopying) { foreach (var toAnnouncementId in toAnnouncementIds) { var attribute = new AnnouncementAssignedAttribute { AnnouncementRef = toAnnouncementId, AttributeTypeId = attributeForCopying.AttributeTypeId, Name = attributeForCopying.Name, Text = attributeForCopying.Text, VisibleForStudents = attributeForCopying.VisibleForStudents, AttachmentRef = attributeForCopying.AttachmentRef, Attachment = attributeForCopying.Attachment }; //if (attributeForCopying.Attachment != null) //{ // var attContent = serviceLocator.AttachementService.GetAttachmentContent(attributeForCopying.Attachment); // if (attContent.Content != null) // { // var att = AttachmentService.Upload(attContent.Attachment.Name, attContent.Content, attContent.Attachment.IsStiAttachment, unitOfWork, serviceLocator, connectorLocator); // attribute.AttachmentRef = att.Id; // attribute.Attachment = att; // } //} attributes.Add(attribute); } } da.Insert(attributes); return(da.GetLastListByAnnIds(toAnnouncementIds, attributes.Count)); }