Esempio n. 1
0
        public async Task<ActionResult> RegisterParticipant(RegisterParticipantViewModel m)
        {
            //Check if inputs were valid
            if (ModelState.IsValid)
            {
                //Create an account so they can login using their username and password
                var user = new ApplicationUser { UserName = m.Username, Email = m.Email };
                var result = await UserManager.CreateAsync(user, m.Password);
                //If the above process succeeds
                if (result.Succeeded)
                {
                    //Sign in as user
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    //Create a person in the database
                    var person = new PX_Model.Person();

                    person.First_Name = m.FirstName;
                    person.Last_Name = m.LastName;
                    person.Phone_Number = m.PhoneNumber;
                    person.Postcode = m.Postcode;
                    person.State = m.State;
                    person.Street = m.Street;
                    person.Suburb = m.Suburb;
                    person.Email = m.Email;
                    person.Username = m.Username;

                    //Push it on to the database
                    _db.People.Add(person);
                    _db.SaveChanges();

                    //Create a participant on the database
                    var participant = new PX_Model.Participant();

                    participant.Person_Id = person.Id;
                    participant.Gender = m.Gender;
                    participant.Date_Of_Birth = m.DateOfBirth;

                    //Push participant on to the database
                    _db.Participants.Add(participant);
                    _db.SaveChanges();

                    //Assign them the role of a participant
                    var u = UserManager.FindByName(m.Username);
                    UserManager.AddToRole(u.Id, "Participant");

                    //We then redirect to the participant dashboard
                    return RedirectToAction("Index", "Participant");
                }
                AddErrors(result);
            }
            //if it fails, go back to the current view and display the errors
            ArrayList gList = new ArrayList();
            gList.Add("Male");
            gList.Add("Female");
            m.GenderList = new SelectList(gList);
            return View(m);
        }
 public ActionResult RegisterParticipant()
 {
     RegisterParticipantViewModel m = new RegisterParticipantViewModel();
     ArrayList gList = new ArrayList();
     gList.Add("Male");
     gList.Add("Female");
     m.GenderList = new SelectList(gList);
     m.DateOfBirth = DateTime.Now;
     return View(m);
 }
        public async Task<ActionResult> RegisterParticipant(RegisterParticipantViewModel m)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = m.Username, Email = m.Email };
                var result = await UserManager.CreateAsync(user, m.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    var person = new PX_Model.Person();

                    person.First_Name = m.FirstName;
                    person.Last_Name = m.LastName;
                    person.Phone_Number = m.PhoneNumber;
                    person.Postcode = m.Postcode;
                    person.State = m.State;
                    person.Street = m.Street;
                    person.Suburb = m.Suburb;
                    person.Email = m.Email;
                    person.Username = m.Username;

                    _db.People.Add(person);
                    _db.SaveChanges();

                    var participant = new PX_Model.Participant();

                    participant.Person_Id = person.Id;
                    participant.Gender = m.Gender;
                    participant.Date_Of_Birth = m.DateOfBirth;

                    _db.Participants.Add(participant);
                    _db.SaveChanges();

                    var u = UserManager.FindByName(m.Username);
                    UserManager.AddToRole(u.Id, "Participant");

                    return RedirectToAction("Index", "Participant");
                }
                AddErrors(result);
            }
            ArrayList gList = new ArrayList();
            gList.Add("Male");
            gList.Add("Female");
            m.GenderList = new SelectList(gList);
            return View(m);
        }
Esempio n. 4
0
        public async Task<ActionResult> Register(RegisterParticipantViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterParticipantViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }