public ActionResult Create([Bind(Include = "UserID,Name,Surname,Username,FK_TitleID,FK_GenderID,FK_RelationshipStatusIdn,FK_ActiveID,FK_CityID,LoginID, userLogin.UserPassword")] myUser myUser, string UserPassword) { userLogin ulogin = new userLogin(); var hasedValue = ComputeSha256Hash(UserPassword); string newHased = hasedValue.Substring(0, 49); if (ModelState.IsValid) { userLogin ul = new userLogin(); ul.UserPassword = newHased; ul.Username = myUser.Username; ul.LoginType = false; db.myUsers.Add(myUser); db.userLogins.Add(ul); db.SaveChanges(); return(RedirectToAction("TopicSelect", "BaeCoach")); } ViewBag.FK_ActiveID = new SelectList(db.Actives, "ActiveID", "ActiveDescription", myUser.FK_ActiveID); ViewBag.FK_CityID = new SelectList(db.Cities, "Id", "Name", myUser.FK_CityID); ViewBag.FK_GenderID = new SelectList(db.Genders, "GenderID", "GenderDescription", myUser.FK_GenderID); ViewBag.FK_RelationshipStatusIdn = new SelectList(db.RelationshipStatus, "RelationshipStatusID", "RelationshipStatusDescription", myUser.FK_RelationshipStatusIdn); ViewBag.FK_TitleID = new SelectList(db.Titles, "TitleID", "Titledescription", myUser.FK_TitleID); ViewBag.LoginID = new SelectList(db.userLogins, "UserLoginID", "Username", myUser.LoginID); return(View(myUser)); }
public ActionResult Create([Bind(Include = "CoachID,Name,Surname,Username,FK_TitleID,FK_GenderID,FK_ActiveID,FK_CityID,LoginID,CoachExperience,University,userLogin.UserPassword")] Coach coach, string UserPassword, string username) { userLogin ulogin = new userLogin(); var hasedValue = ComputeSha256Hash(UserPassword); string newHased = hasedValue.Substring(0, 49); if (ModelState.IsValid) { userLogin ul = new userLogin(); ul.UserPassword = newHased; ul.Username = username; ul.LoginType = true; coach.FK_ActiveID = 1; db.Coaches.Add(coach); db.userLogins.Add(ul); db.SaveChanges(); return(RedirectToAction("TopicSelect", "BaeCoach")); } string ComputeSha256Hash(string rawData) { //Create a SHA256 using (SHA256 sha256Hash = SHA256.Create()) { //Compute hash - returns byte array byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData)); //Convert byte array to a string StringBuilder builder = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { builder.Append(bytes[i].ToString("x2")); } return(builder.ToString()); } } ViewBag.FK_ActiveID = new SelectList(db.Actives, "ActiveID", "ActiveDescription", coach.FK_ActiveID); ViewBag.FK_CityID = new SelectList(db.Cities, "Id", "Name", coach.FK_CityID); ViewBag.CoachExperience = new SelectList(db.ExperienceLevels, "ExperienceID", "ExperienceDescription", coach.CoachExperience); ViewBag.FK_GenderID = new SelectList(db.Genders, "GenderID", "GenderDescription", coach.FK_GenderID); ViewBag.FK_TitleID = new SelectList(db.Titles, "TitleID", "Titledescription", coach.FK_TitleID); ViewBag.LoginID = new SelectList(db.userLogins, "UserLoginID", "Username", coach.LoginID); ViewBag.University = new SelectList(db.Universities, "UniversityID", "UniversityName", coach.University); return(View(coach)); }
public ActionResult Create([Bind(Include = "ResponseID,RespronsText,FK_CoachID,FK_PostID,FK_ResponseID")] Response response, string topic, string PostID) { if (ModelState.IsValid) { // response.FK_PostID = Convert.ToInt32(Session["PostID"]); response.Topic = Convert.ToInt32(Session["TopicId"]); db.Responses.Add(response); db.SaveChanges(); return(RedirectToAction("CoachFeed", "BaeCoach")); } ViewBag.FK_CoachID = new SelectList(db.Coaches, "CoachID", "Name", Session["userID"]); ViewBag.FK_PostID = new SelectList(db.Posts, "PostID", "PostText", Session["PostID"]); ViewBag.FK_ResponseID = new SelectList(db.Responses, "ResponseID", "RespronsText", response.ResponseID); ViewBag.Topic = new SelectList(db.Topics, "TopicID", "TopicName", Session["topicId"]); return(View(response)); }
public ActionResult Create([Bind(Include = "PostID,PostText,FK_UserID,Topic")] Post post) { if (ModelState.IsValid) { post.FK_UserID = Convert.ToInt32(Session["userID"]); post.Topic = Convert.ToInt32(Session["topicId"]); db.Posts.Add(post); db.SaveChanges(); Response newPostID = new Response(); newPostID.FK_PostID = post.PostID; Session["PostId"] = post.PostID; return(RedirectToAction("Home", "BaeCoach")); } ViewBag.FK_UserID = new SelectList(db.myUsers, "UserID", "Name", post.FK_UserID); ViewBag.Topic = new SelectList(db.Topics, "TopicID", "TopicName", post.Topic); return(View(post)); }