public ActionResult createShout(string shoutMessage) { // pull the person making the shout from the // current session string userName = User.Identity.Name; // Declare our database context // using (var db = new Helpers.DAL.CapstoneEntities()) { // Declare a new shout - use the Entity Framework object // to make this easier use object initialization format Helpers.DAL.tShout thisShout = new Helpers.DAL.tShout() { shoutString = shoutMessage, userID = Helpers.HelperQueries.getUserID(userName) }; db.AddTotShouts(thisShout); db.SaveChanges(); var returnShout = new Models.ShoutModel() { shoutString = thisShout.shoutString, userID = Helpers.HelperQueries.GetUserName((int)thisShout.userID) }; // this tshout now contains everything we need to copy it to // a blank object - that we can JSON encode and return to the browser // and use jquery to append it to he html <Span> return Json(returnShout, JsonRequestBehavior.AllowGet); } }
// set this to require authorization public ActionResult createShout(string shoutMessage) { // pull the person making the shout from the // current session string userName = User.Identity.Name; // Declare our database context // using (var db = new Helpers.DAL.CapstoneEntities()) { // Declare a new shout - use the Entity Framework object // to make this easier use object initialization format Helpers.DAL.tShout thisShout = new Helpers.DAL.tShout() { shoutString = shoutMessage, userID = Helpers.HelperQueries.getUserID(userName) }; db.AddTotShouts(thisShout); db.SaveChanges(); var returnShout = new Models.ShoutModel() { shoutString = thisShout.shoutString, userID = Helpers.HelperQueries.GetUserName((int)thisShout.userID) }; // this tshout now contains everything we need to copy it to // a blank object - that we can JSON encode and return to the browser // and use jquery to append it to he html <Span> return(Json(returnShout, JsonRequestBehavior.AllowGet)); } }