Пример #1
0
 public bool AddPost()
 {
     using (Model1Container ctx = new Model1Container())
     {
         bool bResult = false;
         if (this.PostId == 0)
         {
             var it = ctx.Entry <Post>(this).State = EntityState.Added;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
Пример #2
0
 public Post UpdatePost(Post newPost)
 {
     using (Model1Container ctx = new Model1Container())
     {
         Post oldPost = ctx.Posts.Find(newPost.PostId);
         if (oldPost == null) // nu exista in bd
         {
             return(null);
         }
         oldPost.Description = newPost.Description;
         oldPost.Domain      = newPost.Domain;
         oldPost.Date        = newPost.Date;
         ctx.SaveChanges();
         return(oldPost);
     }
 }
Пример #3
0
 public bool CreateCompany(Company companyfromVM)
 {
     Company company;
     bool succes = true;
     try
     {
         using (Model1Container context = new Model1Container())
         {
             company = context.Company.Add(companyfromVM);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         succes = false;
     }
     return succes;
 }
Пример #4
0
 public bool AddComment()
 {
     using (Model1Container ctx = new Model1Container())
     {
         bool bResult = false;
         if (this == null || this.PostPostId == 0)
         {
             return(bResult);
         }
         if (this.CommentId == 0)
         {
             ctx.Entry <Comment>(this).State = EntityState.Added;
             Post p = ctx.Posts.Find(this.PostPostId);
             ctx.Entry <Post>(p).State = EntityState.Unchanged;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
Пример #5
0
 public Comment UpdateComment(Comment newComment)
 {
     using (Model1Container ctx = new Model1Container())
     {
         Comment oldComment = ctx.Comments.Find(newComment.CommentId);
         // Deoarece parametrul este un Comment ar trebui verificata fiecare
         // proprietate din newComment daca are valoare atribuita si
         // daca valoarea este diferita de cea din bd.
         // Acest lucru il fac numai la modificarea asocierii.
         if (newComment.Text != null)
         {
             oldComment.Text = newComment.Text;
         }
         if ((oldComment.PostPostId != newComment.PostPostId) &&
             (newComment.PostPostId != 0))
         {
             oldComment.PostPostId = newComment.PostPostId;
         }
         ctx.SaveChanges();
         return(oldComment);
     }
 }
Пример #6
0
 public bool UpdateCompany(Company companyfromVM)
 {
     Company company;
     bool succes = true;
     try
     {
         using (Model1Container context = new Model1Container())
         {
             company = context.Company.Find(companyfromVM.ID);
             context.Entry(company).CurrentValues.SetValues(companyfromVM);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         succes = false;
     }
     return succes;
 }