public ActionResult Create(Code code) { if (ModelState.IsValid) { db.Codes.Add(code); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", code.UserId); return View(code); }
public ActionResult CodeBox(Code code) { code.IsDeleted = false; code.LastModified = DateTime.Now; code.PostedOn = DateTime.Now; int userId = WebMatrix.WebData.WebSecurity.GetUserId(User.Identity.Name); code.User = db.UserProfiles.Find(userId); if (ModelState.IsValid) { db.Codes.Add(code); db.SaveChanges(); } ModelState.Clear(); return Content("You post has been publsihed", "text/html"); }
public ActionResult Home(int? page, Code code) { code.IsDeleted = false; code.LastModified = DateTime.Now; code.PostedOn = DateTime.Now; int userId = WebMatrix.WebData.WebSecurity.GetUserId(User.Identity.Name); code.User = db.UserProfiles.Find(userId); if (ModelState.IsValid) { db.Codes.Add(code); db.SaveChanges(); } UserProfile user = db.UserProfiles.Find(userId); ViewBag.UserProfile = user; var codes = GetPagedCodes(page); if (codes == null) return HttpNotFound(); // ViewBag.Codes = codes; return View(codes); }
public ActionResult Edit(Code code) { if (ModelState.IsValid) { db.Entry(code).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", code.UserId); return View(code); }