Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] AspNetUser aspNetUser)
        {
            if (ModelState.IsValid)
            {
                db.AspNetUsers.Add(aspNetUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aspNetUser));
        }
Exemplo n.º 2
0
 public static bool AddPost(Post post)
 {
     using (Model2Container ctx = new Model2Container())
     {
         bool bResult = false;
         if (post.PostId == 0)
         {
             var it = ctx.Entry <Post>(post).State = EntityState.Added;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
Exemplo n.º 3
0
 public static Post UpdatePost(Post newPost)
 {
     using (Model2Container ctx = new Model2Container())
     {
         // Ce e in bd. PK nu poate fi modificata
         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);
     }
 }
Exemplo n.º 4
0
 public static Comment UpdateComment(Comment newComment)
 {
     using (Model2Container ctx = new Model2Container())
     {
         Comment oldComment = ctx.Comments.Find(newComment.Id);
         if (newComment.Text != null)
         {
             oldComment.Text = newComment.Text;
         }
         if ((oldComment.PostPostId != newComment.PostPostId) &&
             (newComment.PostPostId != 0))
         {
             oldComment.PostPostId = newComment.PostPostId;
         }
         ctx.SaveChanges();
         return(oldComment);
     }
 }
Exemplo n.º 5
0
 // Comment table
 public static bool AddComment(Comment comment)
 {
     using (Model2Container ctx = new Model2Container())
     {
         bool bResult = false;
         if (comment == null || comment.PostPostId == 0)
         {
             return(bResult);
         }
         if (comment.Id == 0)
         {
             ctx.Entry <Comment>(comment).State = EntityState.Added;
             Post p = ctx.Posts.Find(comment.PostPostId);
             ctx.Entry <Post>(p).State = EntityState.Unchanged;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }