public ActionResult Register(RegisterViewModel model) { var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList<MemberBloodGroup>(), "Id", "BloodGroupName").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList<MemberDistrict>(), "Id", "DistrictName").ToList(); var memberZones = new List<SelectListItem>() { new SelectListItem() { Selected = true, Text = "- Select -", Value = "0" } }.ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList<MemberHospital>(), "Id", "HospitalName").ToList(); model.ddlMemberBloodGroups = memberBloodGroups; model.ddlMemberDistricts = memberDistricts; model.ddlMemberZones = memberZones; model.ddlMemberHospitals = memberHospitals; if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { OSNB.Models.User user = _db.Users.Find(model.UserName); OSNB.Models.Role role = _db.Roles.Find("User"); user.Roles = new List<Role> { role }; _db.Entry(user).State = EntityState.Modified; OSNB.Models.Member member = new OSNB.Models.Member { FirstName = model.UserName, LastName = null, SurName = model.UserName, DateOfBirth = null, Address = null, PhoneNumber = null, MobileNumber = model.ContactNo, ThumbImageUrl = null, SmallImageUrl = null, UserName = model.UserName, MemberBloodGroupId = model.MemberBloodGroupId, MemberDistrictId = model.MemberDistrictId, MemberHospitalId = model.MemberHospitalId, MemberZoneId = model.MemberZoneId }; _db.Members.Add(member); _db.SaveChanges(); FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
// // GET: /Account/Register public ActionResult Register() { var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList<MemberBloodGroup>(), "Id", "BloodGroupName").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList<MemberDistrict>(), "Id", "DistrictName").ToList(); var memberZones = new List<SelectListItem>() { new SelectListItem() { Selected = true, Text = "- Select -", Value = "0" } }.ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList<MemberHospital>(), "Id", "HospitalName").ToList(); var registerViewModel = new RegisterViewModel { ddlMemberBloodGroups = memberBloodGroups, ddlMemberDistricts = memberDistricts, ddlMemberHospitals = memberHospitals, ddlMemberZones = memberZones }; return View(registerViewModel); }