Пример #1
0
        public void PutComment([FromBody] Comment comment)
        {
            Comment dbComment = context.Comments.FirstOrDefault(x => x.Id == comment.Id);

            dbComment.Clone(comment);
            context.SaveChanges();
        }
        public async Task <IModelServiceResponse <Comment> > Create(ActionContext actionContext, Comment comment)
        {
            comment = comment.Clone();

            string userID = GetUserID(actionContext.HttpContext.User);

            if (userID != "")
            {
                comment.UserID = userID;
            }

            ValidationStateDictionary validationState = TryValidateModel(actionContext, comment);

            if (!validationState.IsValid()) //If Comment does not have validation errors
            {
                return(new ModelServiceResponse <Comment>(comment, validationState, HttpStatusCode.BadRequest));
            }

            try
            {
                //Save the comment to the database
                _context.Add(comment);
                await _context.SaveChangesAsync();

                //
                return(new ModelServiceResponse <Comment>(comment, validationState, HttpStatusCode.Created));
            }
            catch
            {
                //
                return(new ModelServiceResponse <Comment>(null, validationState, HttpStatusCode.InternalServerError));
            }
        }
Пример #3
0
        protected override bool CloneEntity(IDiagram diagram)
        {
            if (diagram.DiagramType != DiagramType.ClassDiagram)
            {
                return(false);
            }

            return(((ClassDiagram)diagram).InsertComment(Comment.Clone()));
        }
Пример #4
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public new DateTimeError Clone()
        {
            var datetimeErrorCloned = (DateTimeError)MemberwiseClone();

            datetimeErrorCloned.Comment    = Comment.Clone();
            datetimeErrorCloned.Properties = Properties.Clone();

            return(datetimeErrorCloned);
        }
Пример #5
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public new PercentageErrorModel Clone()
        {
            var percentageErrorCloned = (PercentageErrorModel)MemberwiseClone();

            percentageErrorCloned.Comment    = Comment.Clone();
            percentageErrorCloned.Properties = Properties.Clone();

            return(percentageErrorCloned);
        }
Пример #6
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public new NumericError Clone()
        {
            var numericErrorCloned = (NumericError)MemberwiseClone();

            numericErrorCloned.Comment    = Comment.Clone();
            numericErrorCloned.Properties = Properties.Clone();

            return(numericErrorCloned);
        }
Пример #7
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public new ScientificErrorModel Clone()
        {
            var scientificErrorCloned = (ScientificErrorModel)MemberwiseClone();

            scientificErrorCloned.Comment    = Comment.Clone();
            scientificErrorCloned.Properties = Properties.Clone();

            return(scientificErrorCloned);
        }
Пример #8
0
        public override IPalasoDataObjectProperty Clone()
        {
            var clone = new LexEtymology(Type, Source);

            clone.Gloss   = (MultiText)Gloss.Clone();
            clone.Comment = (MultiText)Comment.Clone();
            clone.Traits  = new List <LexTrait>(Traits.Select(t => t.Clone()));
            clone.Fields  = new List <LexField>(Fields.Select(f => (LexField)f.Clone()));
            //copies from MultiText
            clone.EmbeddedXmlElements = new List <string>(EmbeddedXmlElements);
            clone.Forms = Forms.Select(f => (LanguageForm)f.Clone()).ToArray();
            return(clone);
        }
Пример #9
0
        /// <summary>
        /// Used to duplicate all properties. Any property added must be duplicated here as well.
        /// </summary>
        /// <param name="newnode">The new node which is supposed to get a copy of the properties.</param>
        protected virtual void CloneProperties(Node newnode)
        {
            // clone attachements
            foreach (Attachments.Attachment attach in _attachments)
            {
                newnode.AddAttachment(attach.Clone(newnode));
            }

            // clone comment
            if (_comment != null)
            {
                newnode._comment = _comment.Clone();
            }
        }
Пример #10
0
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var original = new Comment
            {
                Body = "Random body"
            };

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
        public async Task <IModelServiceResponse <Comment> > Reply(ActionContext actionContext, Comment comment)
        {
            comment = comment.Clone();

            //If new comment has a parent Comment ID, set the comment to have the same Work ID as the parent Comment.
            if (comment.ParentID != null)
            {
                Comment parentComment = await _context.Comment.FindAsync(comment.ParentID);

                if (parentComment != null)
                {
                    comment.WorkID = parentComment.WorkID;
                }
            }

            return(await Create(actionContext, comment));
        }
Пример #12
0
        /// <summary>
        /// Used to duplicate all properties. Any property added must be duplicated here as well.
        /// </summary>
        /// <param name="newnode">The new node which is supposed to get a copy of the properties.</param>
        protected virtual void CloneProperties(Node newnode)
        {
            // clone attachements
            foreach (Attachments.Attachment attach in _attachments)
            {
                newnode.AddAttachment(attach.Clone(newnode));
            }

            System.Type type = this.GetType();
            foreach (System.Reflection.FieldInfo fi in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public))
            {
                if (fi.DeclaringType == type)
                {
                    fi.SetValue(newnode, fi.GetValue(this));
                }
            }
            // clone comment
            if (_comment != null)
            {
                newnode._comment = _comment.Clone();
            }
        }
Пример #13
0
 protected override bool CloneEntity(Diagram diagram)
 {
     return(diagram.InsertComment(Comment.Clone()));
 }