Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 21st, 2013  |  syntax: C#  |  size: 2.56 KB  |  views: 101  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public ActionResult Register()
  2.         {
  3.             var hmc = hmcRepository.GetAll();
  4.             var cities = cityRepository.GetAll();
  5.             var streets = streetRepository.GetByCityId(1)//default city id
  6.             var houses = new List<House>();
  7.  
  8.             var model = new RegisterModel
  9.                 {
  10.                     CityList = new SelectList(cities, "Id", "Name"),
  11.                     HmcList = new SelectList(hmc, "Id", "Name"),
  12.                     StreetList = new SelectList(streets, "Id", "Name"),
  13.                     HouseList = new SelectList(houses, "Id", "Number")
  14.                 };
  15.            
  16.             return View(model);
  17.         }
  18.  
  19. public ActionResult GetStreets(int id)
  20.         {
  21.             return this.Json(streetRepository.GetByCityId(id), JsonRequestBehavior.AllowGet);
  22.         }
  23.  
  24.         public ActionResult GetHouses(int id)
  25.         {
  26.             return this.Json(houseRepository.GetAllByStreetId(id), JsonRequestBehavior.AllowGet);
  27.         }
  28.  
  29.  [HttpPost]
  30.         public ActionResult Register(RegisterModel model)
  31.         {
  32.             if (ModelState.IsValid)
  33.             {
  34.                 // Attempt to register the user
  35.                 MembershipCreateStatus createStatus;
  36.                 Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus);
  37.  
  38.                 if (createStatus == MembershipCreateStatus.Success)
  39.                 {
  40.                     FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);
  41.                     Roles.AddUserToRole(model.Email, "customer");
  42.                     return RedirectToAction("Index", "Home");
  43.                 }
  44.                 else
  45.                 {
  46.                     ModelState.AddModelError("", ErrorCodeToString(createStatus));
  47.                 }
  48.             }
  49.  
  50.             // If we got this far, something failed, redisplay form
  51.             var hmc = hmcRepository.GetAll();
  52.             var cities = cityRepository.GetAll();
  53.             var streets = streetRepository.GetByCityId(Convert.ToInt32(model.SelectedCity));
  54.             var houses = houseRepository.GetAllByStreetId(Convert.ToInt32(model.SelectedStreet));
  55.             model = new RegisterModel
  56.             {
  57.                 CityList = new SelectList(cities, "Id", "Name"),
  58.                 HmcList = new SelectList(hmc, "Id", "Name"),
  59.                 StreetList = new SelectList(streets, "Id", "Name"),
  60.                 HouseList = new SelectList(houses, "Id", "Number")
  61.             };
  62.             return View(model);
  63.         }
clone this paste RAW Paste Data