/// <summary>
 /// Deprecated Method for adding a new object to the Annotations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAnnotations(Annotation annotation)
 {
     base.AddObject("Annotations", annotation);
 }
 /// <summary>
 /// Create a new Annotation object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="upVotes">Initial value of the UpVotes property.</param>
 /// <param name="downVotes">Initial value of the DownVotes property.</param>
 public static Annotation CreateAnnotation(global::System.Int32 id, global::System.Int32 upVotes, global::System.Int32 downVotes)
 {
     Annotation annotation = new Annotation();
     annotation.ID = id;
     annotation.UpVotes = upVotes;
     annotation.DownVotes = downVotes;
     return annotation;
 }
Пример #3
0
        private void saveAnnotation(object state)
        {
            var annotationAndTags = (annotationAndTags)state;

            Annotation annotation = new Annotation() {
                StartIndex = currentSelection.CharIndex,
                SourceLength = currentSelection.CharLength,
                SourceText = currentText.ID,
                Content = annotationAndTags.Annotation,
                Author = currentUser.ID,
                UpVotes = 0,
                DownVotes = 0,
                HighlightedSourceText = string.Concat((this.textRoot.SelectedContent.Content as TextControl).body.Selection.Text.Take(100)),
                Timestamp = DateTime.Now
            };

            db.Annotations.AddObject(annotation);
            db.SaveChanges();

            List<int> tagIDs = new List<int>();
            List<string> inputTags = annotationAndTags.Tags;
            foreach (var tag in inputTags) {
                var resolvedTag = db.Tags.Where(i => i.Name == tag).SingleOrDefault();
                if (resolvedTag == null) {
                    var newTag = new Tag() { Name = tag };
                    db.Tags.AddObject(newTag);
                    db.SaveChanges();
                    tagIDs.Add(newTag.ID);
                } else {
                    tagIDs.Add(resolvedTag.ID);
                }
            }

            foreach (var id in tagIDs) {
                var annotationTag = new AnnotationTag() { AnnotationID = annotation.ID, TagID = id };
                db.AnnotationTags.AddObject(annotationTag);
                db.SaveChanges();
            }

            Dispatcher.Invoke((Action)(() => {
                loadAnnotations();
            }));
        }