Beispiel #1
0
        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);
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 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);
 }