// GET: AdminDashboard/Create        
 public ActionResult Create()
 {
     ViewBag.FullName = getUserName();
     ViewBag.spcID = new SelectList(db.Specialties, "spcID", "spcName");
     ViewBag.viewName = "create";
     Volunteer volunteer = new Volunteer();
     //sets every newly created volunteer to active as default
     volunteer.volActive = true;
     return View(volunteer);
 }
        ////
        //// GET: /Account/Register
        //[AllowAnonymous]
        //public ActionResult Register()
        //{
        //    return View();
        //}

        ////
        //// POST: /Account/Register
        //[HttpPost]
        //[AllowAnonymous]
        //[ValidateAntiForgeryToken]
        //public async Task<ActionResult> Register(RegisterViewModel 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)
        //        {
        //            UserManager.AddToRole(user.Id, "Volunteer");
        //            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);
        //}

        public async Task<ActionResult> RegisterNewVol(Volunteer vol)
        {
            //var errors = ModelState.Values.SelectMany(v => v.Errors);
            if (vol != null)
            {
                var user = new ApplicationUser { UserName = vol.volEmail, Email = vol.volEmail };
                user.Volunteer = vol; //add vol to volunteer table, sets user object's Volunteer attribute to vol

                //default password start
                String firstName = vol.volFirstName.Trim().Substring(0,1).ToUpper();
                String lastName = vol.volLastName.Trim().ToLower();
                String year = vol.volDOB.Year.ToString().Trim();
                String password = String.Concat(firstName, lastName, year, "!");
                //ToDO: catch an error if last name doesn't have 3 letters, in that case set it to "Password1!"

                //default password end

                var result = await UserManager.CreateAsync(user, password); //create autogen password logic here
                if (result != null)
                {
                    UserManager.AddToRole(user.Id, "Volunteer");
                   // await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    return RedirectToAction("Index", "AdminDashboard"); // redirect to desired view, needs success message
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return RedirectToAction("Index", "Home");
        }