Example #1
0
        public override void Submit(int announcementId)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            var res = GetAnnouncementDetails(announcementId);

            if (res.ClassAnnouncementData.Title == null || Exists(res.ClassAnnouncementData.Title, res.ClassAnnouncementData.ClassRef, res.ClassAnnouncementData.Expires, res.ClassAnnouncementData.Id))
            {
                throw new ChalkableException("Invalid Class Announcement Title");
            }

            using (var uow = Update())
            {
                var da = CreateClassAnnouncementDataAccess(uow);
                AnnouncementSecurity.EnsureInModifyAccess(res, Context);
                if (res.ClassAnnouncementData.IsDraft)
                {
                    ServiceLocator.AnnouncementAssignedAttributeService.ValidateAttributes(res.AnnouncementAttributes);
                    res.ClassAnnouncementData.State   = AnnouncementState.Created;
                    res.ClassAnnouncementData.Created = Context.NowSchoolTime.Date;

                    var activity = new Activity();
                    MapperFactory.GetMapper <Activity, AnnouncementDetails>().Map(activity, res);
                    activity = ConnectorLocator.ActivityConnector.CreateActivity(res.ClassAnnouncementData.ClassRef, activity);
                    if (da.Exists(activity.Id))
                    {
                        throw new ChalkableException("Announcement with such activityId already exists");
                    }

                    var annAttDa = new AnnouncementAssignedAttributeDataAccess(uow);
                    annAttDa.Delete(res.AnnouncementAttributes);
                    MapperFactory.GetMapper <AnnouncementDetails, Activity>().Map(res, activity);
                    var attributes = res.AnnouncementAttributes.Where(x => x.Attachment != null).ToList();
                    if (attributes.Count > 0)
                    {
                        var atts = new AttachmentDataAccess(uow).GetBySisAttachmentIds(attributes.Select(a => a.Attachment.SisAttachmentId.Value).ToList());
                        foreach (var attribute in res.AnnouncementAttributes)
                        {
                            if (attribute.Attachment == null)
                            {
                                continue;
                            }
                            var att = atts.FirstOrDefault(x => x.SisAttachmentId == attribute.Attachment.SisAttachmentId);
                            if (att == null)
                            {
                                continue;
                            }
                            attribute.AttachmentRef = att.Id;
                        }
                    }
                    annAttDa.Insert(res.AnnouncementAttributes);
                }
                da.Update(res.ClassAnnouncementData);
                uow.Commit();
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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));
        }