public ActionResult Index(AddressModel model) { var vSessionValue = new User(); var stateId = model.StateId; var selectedId = model.CityId; try { // check existing value into session if ((Object)Session["UserId"] != null) { // assign value into properties vSessionValue.SessionValue = "Welcome " + Session["UserID"].ToString(); } else // if session expired than set custom message vSessionValue.SessionValue = "Session Expired"; } catch { } // return value to view //return View(vSessionValue); return RedirectToAction("Index1", "Main", new { Id = selectedId, clickinfo="hotels",sessionvalue= vSessionValue }); }
public ActionResult Register(User user) { if (ModelState.IsValid) { using (var db = new HolidayPlanner.Models.Register()) { var newUser = db.Users.Create(); int lastUserId = db.Users.Max(item => item.UserId); //added by Sandy for ID Auto-Increment user.UserId = lastUserId + 1; newUser.UserId = user.UserId; var test = (newUser.UserId); newUser.UserName = user.UserName; newUser.EmailId = user.EmailId; newUser.ContactNo = user.ContactNo; newUser.Password = user.Password; db.Users.Add(newUser); db.SaveChanges(); using (var db2 = new HolidayPlanner.Models.UserInRoleContext()) { var userrole = db2.UserInRoles.Create(); { userrole.UserId = test; userrole.RoleId = 1; db2.UserInRoles.Add(userrole); db2.SaveChanges(); } } ViewBag.Message = "Registration Successfully Done "; return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "Data is not correct"); } ViewBag.Message = "Please register yourself"; return View(); }