public ActionResult Create([Bind(Include = "RobotID,RobotName")] Robot robot) { if (ModelState.IsValid) { if (robot.RobotName.Length > 50) { ModelState.AddModelError("RobotName", "Robot's name is too long. Please pick a shorter name"); return View(robot); } if (db.Robots.Count(t => t.RobotName == robot.RobotName) > 0) { ModelState.AddModelError("RobotName", "A Robot already exists with that name"); return View(robot); } using(System.Net.WebClient wc = new WebClient()) { String result = wc.DownloadString("http://www.wdyl.com/profanity?q=" + Url.Encode(robot.RobotName.Replace(".", " "))); if(result.Contains("true")) { ModelState.AddModelError("RobotName", "Google Finds that name Offensive. Please select another."); return View(robot); } } Models.Robot r = new Robot(); r.RobotID = robot.RobotID; r.OwnerApplicationUserID = User.Identity.GetUserId(); r.RobotName = robot.RobotName; r.isPublic = false; r.BotXML = "<xml xmlns=\"http://www.w3.org/1999/xhtml\"></xml>"; db.Robots.Add(r); db.SaveChanges(); return RedirectToAction("Edit", new { id = r.RobotID }); } return View(robot); }
public ActionResult Edit(Int32? id) { if(!this.Request.IsAuthenticated || id == null || id == 0) { Robot temp = new Robot() { RobotID = -1, RobotName = "TempBot", OwnerApplicationUserID = String.Empty, isPublic = false, BotXML = "<xml xmlns=\"http://www.w3.org/1999/xhtml\"></xml>" }; return View(temp); } Robot robot = db.Robots.Find(id); if (robot == null) { return HttpNotFound(); } if(robot.OwnerApplicationUserID != User.Identity.GetUserId()) { return HttpNotFound(); } return View(robot); }