Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Register()
- {
- var hmc = hmcRepository.GetAll();
- var cities = cityRepository.GetAll();
- var streets = streetRepository.GetByCityId(1)//default city id
- var houses = new List<House>();
- var model = new RegisterModel
- {
- CityList = new SelectList(cities, "Id", "Name"),
- HmcList = new SelectList(hmc, "Id", "Name"),
- StreetList = new SelectList(streets, "Id", "Name"),
- HouseList = new SelectList(houses, "Id", "Number")
- };
- return View(model);
- }
- public ActionResult GetStreets(int id)
- {
- return this.Json(streetRepository.GetByCityId(id), JsonRequestBehavior.AllowGet);
- }
- public ActionResult GetHouses(int id)
- {
- return this.Json(houseRepository.GetAllByStreetId(id), JsonRequestBehavior.AllowGet);
- }
- [HttpPost]
- public ActionResult Register(RegisterModel model)
- {
- if (ModelState.IsValid)
- {
- // Attempt to register the user
- MembershipCreateStatus createStatus;
- Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus);
- if (createStatus == MembershipCreateStatus.Success)
- {
- FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);
- Roles.AddUserToRole(model.Email, "customer");
- return RedirectToAction("Index", "Home");
- }
- else
- {
- ModelState.AddModelError("", ErrorCodeToString(createStatus));
- }
- }
- // If we got this far, something failed, redisplay form
- var hmc = hmcRepository.GetAll();
- var cities = cityRepository.GetAll();
- var streets = streetRepository.GetByCityId(Convert.ToInt32(model.SelectedCity));
- var houses = houseRepository.GetAllByStreetId(Convert.ToInt32(model.SelectedStreet));
- model = new RegisterModel
- {
- CityList = new SelectList(cities, "Id", "Name"),
- HmcList = new SelectList(hmc, "Id", "Name"),
- StreetList = new SelectList(streets, "Id", "Name"),
- HouseList = new SelectList(houses, "Id", "Number")
- };
- return View(model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement