How to access 'name' given when user registers
-
So I only want the logged in user to be allowed to book holidays for them selves. I think the easiest way to do this is to compare 'name' of logged in user againast 'name' in person table. So....
public ActionResult Create()
{
string xx = (string)Session["usernameID"];
int? currentPersonID = Convert.ToInt32(xx);string userNameComparedAgainstLoginName = // here is where i want to say 'name' of logged in user CreateModel model = new CreateModel(); model.currentPersonID = currentPersonID.Value; model.PList4DD = db.People.ToList(); if (userNameComparedAgainstLoginName == model.userName) { ViewBag.Id = new SelectList(db.People, "Id", "Name"); return View(model); } else { TempData\["canOnlyBookHolidaysForYourself"\] = "I'm afraid you can only book holidays for yourself"; return RedirectToAction("Index"); } }
--------------------------------------- the name given when the user registers will be the same names used in the db. So could someone tell me how I can access the logged in 'name'? Thanks
-
So I only want the logged in user to be allowed to book holidays for them selves. I think the easiest way to do this is to compare 'name' of logged in user againast 'name' in person table. So....
public ActionResult Create()
{
string xx = (string)Session["usernameID"];
int? currentPersonID = Convert.ToInt32(xx);string userNameComparedAgainstLoginName = // here is where i want to say 'name' of logged in user CreateModel model = new CreateModel(); model.currentPersonID = currentPersonID.Value; model.PList4DD = db.People.ToList(); if (userNameComparedAgainstLoginName == model.userName) { ViewBag.Id = new SelectList(db.People, "Id", "Name"); return View(model); } else { TempData\["canOnlyBookHolidaysForYourself"\] = "I'm afraid you can only book holidays for yourself"; return RedirectToAction("Index"); } }
--------------------------------------- the name given when the user registers will be the same names used in the db. So could someone tell me how I can access the logged in 'name'? Thanks
forgot to mention Its just the automatic login that comes with mvc3 razor