public ActionResult AddOrEdit(UserViewModel uvm) { if (uvm.Username == null || uvm.Password == null) { ViewBag.RegistrationMsg = "Enter in username and password."; } else if (!uvm.Password.Equals(uvm.ConfirmPassword)) { ViewBag.RegistrationMsg = "Password and confirm password do not match."; } else { db = new ArticleDatabaseEntities(); User newUser = new User { Username = uvm.Username, Password = uvm.Password }; db.Users.Add(newUser); db.SaveChanges(); ModelState.Clear(); ViewBag.RegistrationMsg = "Registration successful!"; } return(View("AddOrEdit", new UserViewModel())); }
public HttpStatusCode AddComment(string comment, int articleId) { if (Session["userId"] == null) { return(HttpStatusCode.Unauthorized); } //make comment Comment newcomment = new Comment(); newcomment.ArticleId = articleId; newcomment.UserId = (int)Session["userId"]; newcomment.Text = comment; db.Comments.Add(newcomment); db.SaveChanges(); return(HttpStatusCode.OK); }