Ejemplo n.º 1
0
 public MenuViewModel(User user)
 {
     Pools = new SelectList(user.GetPools(),"Id","Name").ToList();
     Teams = new List<Team>();
     //foreach (var pool in user.GetPools())
     //    Pools.Add(new SelectListItem() { Text = pool.Name, Value = pool.Id.ToString() });
     if (Pools.Count != 0)
     {
         SelectedPoolId = Int32.Parse(Pools.First().Value);
         Teams = new ApplicationDbContext().TeamsByPoolID(SelectedPoolId);
     }
 }
Ejemplo n.º 2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = new User { UserName = model.Email, Email = model.Email, Name = model.Name };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        using (var db = new ApplicationDbContext())
                        {
                            db.UserTeams.Add(new UserTeam() { UserId = user.Id, TeamId = model.SelectedTeamId });
                            db.SaveChanges();
                        }
                        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);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                                validationError.PropertyName,
                                                validationError.ErrorMessage);
                    }
                }
            }

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