private IEnumerable<RoleModel> GetRolesByUser(ApplicationUser user)
 {
     try
     {
         var names = UserManager.GetRoles(user.Id);
         var roles = names.Select(id => RoleManager.Roles.FirstOrDefault(role => role.Name == id)).ToList();
         return roles.Select(x => (RoleModel)x);
     }
     catch(Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(new PermissionException(String.Format("При попытке получения ролей пользователя {0} возникла ошибка.", user.UserName), ex));
         return null;
     }
     
 }
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await UserManager.AddToRoleAsync(user.Id, "user");
                    return RedirectToAction("Index");
                }

                foreach (string error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                }
            }
            return View(model);
        }          
 public UserModel(ApplicationUser user, IEnumerable<RoleModel> roles)
     : this(user.UserName, roles)
 {
     Id = user.Id;
 }