public ActionResult Register([Bind(Include = "Id,Username,Password,ConfirmPassword,Title,Forename,Surname,Dob,AddressStreet," + "AddressTown,AddressCounty,AddressPostalCode,HomePhoneNo,WorkPhoneNo,MobilePhoneNo,Email")] RegisterVM registration) { if (ModelState.IsValid) { if (_authFacade.Register(registration.Username, registration.Password, registration.ConfirmPassword)) { _authFacade.GetToken(registration.Username, registration.Password); GenericFacade.UserName = registration.Username; string owinId = _authFacade.GetUserId(); GenericFacade.OwinId = owinId; _authFacade.AddCustomerRole(); Session[Global.RolesSessionVar] = GenericFacade.IsAdmin; _customerFacade.Create(new Customer { OwinUserId = owinId, UserName = registration.Username, Title = registration.Title, Forename = registration.Forename, Surname = registration.Surname, DoB = registration.Dob, AddressStreet = registration.AddressStreet, AddressTown = registration.AddressTown, AddressCounty = registration.AddressCounty, AddressPostalCode = registration.AddressPostalCode, HomePhoneNo = registration.HomePhoneNo, WorkPhoneNo = registration.WorkPhoneNo, MobilePhoneNo = registration.MobilePhoneNo, Email = registration.Email }); Customer c = _customerFacade.Get(); Session[Global.UserIdSessionVar] = c.Id; Session[Global.UsernameSessionVar] = registration.Username; return(RedirectToAction("index", "home")); } else { return(View(registration)); } } return(View(registration)); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ((MainActivity)Activity).SetAsDrawerToolbar(); var ignored = base.OnCreateView(inflater, container, savedInstanceState); view = inflater.Inflate(Resource.Layout.register, null); customer = new Customer(); List <string> titles = new List <string> { "Please select a title" }; titles.AddRange(Enum.GetNames(typeof(Title)).ToList()); Spinner titleSpinner = view.FindViewById <Spinner>(Resource.Id.register_title); var adapter = new ArrayAdapter <string>(Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, titles); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); titleSpinner.Adapter = adapter; int initialSpinnerPosition = titleSpinner.SelectedItemPosition; titleSpinner.ItemSelected += (sender, args) => { if (args.Position != initialSpinnerPosition) { customer.Title = titles[args.Position]; } }; Button register = view.FindViewById <Button>(Resource.Id.register_btn); register.Click += delegate { string password = view.FindViewById <TextView>(Resource.Id.register_password).Text; string confirmPassword = view.FindViewById <TextView>(Resource.Id.register_password_confirm).Text; customer.UserName = view.FindViewById <TextView>(Resource.Id.register_username).Text; customer.Forename = view.FindViewById <TextView>(Resource.Id.register_forename).Text; customer.Surname = view.FindViewById <TextView>(Resource.Id.register_surname).Text; customer.DoB = view.FindViewById <DatePicker>(Resource.Id.register_dob).DateTime; customer.AddressStreet = view.FindViewById <TextView>(Resource.Id.register_street).Text; customer.AddressTown = view.FindViewById <TextView>(Resource.Id.register_town).Text; customer.AddressCounty = view.FindViewById <TextView>(Resource.Id.register_county).Text; customer.AddressPostalCode = view.FindViewById <TextView>(Resource.Id.register_postal_code).Text; customer.HomePhoneNo = view.FindViewById <TextView>(Resource.Id.register_home_phone_no).Text; customer.WorkPhoneNo = view.FindViewById <TextView>(Resource.Id.register_work_phone_no).Text; customer.MobilePhoneNo = view.FindViewById <TextView>(Resource.Id.register_mobile_phone_no).Text; customer.Email = view.FindViewById <TextView>(Resource.Id.register_email_address).Text; if (Validate()) { if (_authFacade.Register(customer.UserName, password, confirmPassword)) { _authFacade.GetToken(customer.UserName, password); GenericFacade.UserName = customer.UserName; string owinId = _authFacade.GetUserId(); GenericFacade.OwinId = owinId; _authFacade.AddCustomerRole(); customer.OwinUserId = owinId; Customer newCustomer = _customerFacade.Create(customer).Result; GenericFacade.UserId = newCustomer.Id; Toast.MakeText(Activity, "Registration successful", ToastLength.Long).Show(); Fragment fragment = HomeFragment.NewInstance(); FragmentManager.BeginTransaction() .Replace(Resource.Id.content_frame, fragment) .Commit(); ((MainActivity)Activity).ToggleLogin(); } else { Toast.MakeText(Activity, "An error occured whilst registering. Please try again later", ToastLength.Long).Show(); } } else { Toast.MakeText(Activity, "Validation errors detected", ToastLength.Long).Show(); } }; return(view); }
private async Task GetValues() { _authFacade.GetToken(username, password); customer = await _customerFacade.Get(); }