public ActionResult Create([Bind(Include = "UserId,UserName,UserPassword,UserType,UserEmail,UserProfilePicture")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "PostId,PostTitle,PostType,PostDate,PostImage,PostContent,UserId")] Post post) { if (ModelState.IsValid) { db.Posts.Add(post); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.Users, "UserId", "UserName", post.UserId); return(View(post)); }
public ActionResult Create([Bind(Include = "CommentId,CommentContent,CommentDate,UserId,PostId")] Comment comment) { if (ModelState.IsValid) { db.Comments.Add(comment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostId = new SelectList(db.Posts, "PostId", "PostTitle", comment.PostId); ViewBag.UserId = new SelectList(db.Users, "UserId", "UserName", comment.UserId); return(View(comment)); }
public ActionResult edit_profile(User u) { string login_type = "0"; if (Session["login_type"] != null) { u.UserId = Convert.ToInt32(Session["user_id"]); login_type = "session"; } else if (Request.Cookies["user_info"] != null) { login_type = "cookie"; u.UserId = Convert.ToInt32(Request.Cookies["user_info"]["user_id"]); } var user = db.Users.FirstOrDefault(c => c.UserId == u.UserId); if (u.UserName != null) { user.UserName = u.UserName; if (login_type == "session") { Session["user_name"] = user.UserName; } else if (login_type == "cookie") { HttpCookie cookie = new HttpCookie("user_info"); cookie.Values["user_name"] = user.UserName; cookie.Values["user_type"] = user.UserType; cookie.Values["user_id"] = user.UserId.ToString(); cookie.Values["login_type"] = "cookie"; cookie.Expires = DateTime.Now.AddDays(10); Response.SetCookie(cookie); } } if (u.UserEmail != null) { user.UserEmail = u.UserEmail; } if (u.UserPassword != null) { user.UserPassword = u.UserPassword; user.ConfirmPassword = u.ConfirmPassword; } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult delete_comment(int delete_id, int post_id) { var comment = new Comment { CommentId = delete_id }; db.Comments.Attach(comment); db.Comments.Remove(comment); db.SaveChanges(); return(RedirectToAction("post_view/" + post_id)); }
public ActionResult Index([Bind(Include = "UserName,UserPassword,ConfirmPassword,UserEmail")] User u) { using (SiliconTechDBContext db = new SiliconTechDBContext()) { if (ModelState.IsValid) { u.UserProfilePicture = "dummy_value"; u.UserType = "admin"; db.Users.Add(u); db.SaveChanges(); // u = null; ViewBag.Message = "Registered successfully"; //TempData["Message"] = "Registered successfully now you can log in"; } else { ModelState.AddModelError("", "Check for incorrect fields"); } } return(View(u)); }