Ejemplo n.º 1
0
        public async Task<ActionResult> RegisterAsACoach(RegisterAsCoachViewModel vm)
        {

                if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = vm.UserName };

                user = Mapper.Map<RegisterAsCoachViewModel, ApplicationUser>(vm);

                ////extended prtops
                //user.WebSite = vm.WebSite;
                //user.FirstName = vm.FirstName;
                //user.SecondName = vm.SecondName;
                //user.Phone = vm.Phone;
                //user.MobilePhone = vm.MobilePhone;

                //user.Address = new CoachAddress()
                //{
                //    AddressLine1 = vm.Address.AddressLine1,
                //    AddressLine2=vm.Address.AddressLine2,
                //    AddressLine3=vm.Address.AddressLine3,
                //    City=vm.Address.City,
                //    Country = vm.Address.Country,
                //    County=vm.Address.County,
                //    PostalCode=vm.Address.PostalCode

                //};
                //user.Coach1 = vm.Coach1;
                ////user.Coach2 = vm.Coach2;

                //user.Referral = CoachReferral.Email.ToString();

                //user.Subscriber = false;
                //user.SubscriptionEnd = new DateTime(3000,1,1);

                //user.Roles.Add(new IdentityUserRole() {  UserId=user.Id, RoleId= Roles.GetAllRoles(). })

                var result = await UserManager.CreateAsync(user, vm.Password);
                if (result.Succeeded)
                {

                    var account = new AccountController();
                    account.UserManager.AddToRole(user.Id, "Coach");

                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Coach", new { id = user.Id });
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(vm);
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Register(RegisterAsCoachViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

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