Ejemplo n.º 1
0
        public override void Save(LinearRegressionDbContext db)
        {
            if (this.Entity is null)
            {
                this.Entity = new Model.Comment(this.AnalysisInformationId, this.User, this.Content);
            }

            else
            {
                this.Entity.Content = this.Content;
            }

            if (db.CommentSet.Any(c => c.Id == this.Entity.Id))
            {
                db.CommentSet.Update(this.Entity);
            }

            else
            {
                db.CommentSet.Add(this.Entity);
            }

            db.SaveChanges();

            //Adding the comment after saving it so the id is correct.
            var analysisInformation = db.AnalysisInformationSet.Find(this.AnalysisInformationId);

            analysisInformation.AddComment(this.Entity);
            db.AnalysisInformationSet.Update(analysisInformation);
            db.SaveChanges();

            this.Id = this.Entity.Id;
        }
Ejemplo n.º 2
0
        public override void Delete(LinearRegressionDbContext db)
        {
            if (this.Id != 0)
            {
                db.CommentSet.Remove(this.Entity);
                var analysisInformation = db.AnalysisInformationSet.Find(Entity.AnalysisInformationID);
                analysisInformation.RemoveComment(this.Entity);

                db.SaveChanges();
            }

            else
            {
                throw new InvalidOperationException("Unsaved data cannot be deleted.");
            }
        }