private void SetDefaultValues(ApplicationUser user)
        {
            int defaultId = 1;

            user.Activity = DbContext.Activities.Find(defaultId);
            user.Alcohol = DbContext.Alcohols.Find(defaultId);
            user.DesiredAge = DbContext.DesiredAges.Find(defaultId);
            user.Education = DbContext.Educations.Find(defaultId);
            user.EyeColor = DbContext.EyeColors.Find(defaultId);
            user.HairColor = DbContext.HairColors.Find(defaultId);
            user.Hobby = DbContext.Hobbies.Find(defaultId);
            user.InternationalPassport = DbContext.InternationalPassports.Find(defaultId);
            user.Job = DbContext.Jobs.Find(defaultId);
            user.Knowledge = DbContext.Knowledges.Find(defaultId);
            user.FirstLanguage = DbContext.Languages.Find(defaultId);
            user.FirstLanguageLevel = DbContext.Levels.Find(defaultId);
            user.SecondLanguage = DbContext.Languages.Find(defaultId);
            user.SecondLanguageLevel = DbContext.Levels.Find(defaultId);
            user.ThirdLanguage = DbContext.Languages.Find(defaultId);
            user.ThirdLanguageLevel = DbContext.Levels.Find(defaultId);
            user.Lifestyle = DbContext.Lifestyles.Find(defaultId);
            user.Location = DbContext.Locations.Find(defaultId);
            user.NumberOfChildren = DbContext.NumbersOfChildren.Find(defaultId);
            user.Relationship = DbContext.Relationships.Find(defaultId);
            user.Religion = DbContext.Religions.Find(defaultId);
            user.Shape = DbContext.Shapes.Find(defaultId);
            user.Smoking = DbContext.Smokings.Find(defaultId);

            user.Birthday = new DateTime(1900, 1, 1);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    OpenPassword = model.Password,
                    CreationDate = DateTime.Now,
                    LastLoginTime = DateTime.Now,
                    FilePaths = new List<FilePath>(),
                };

                SetDefaultValues(user);

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await UserManager.AddToRoleAsync(user.Id, "user");
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    var 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 View("DisplayEmail");

                }
                AddErrors(result);

            }

            // If we got this far, something failed, redisplay form
            ViewBag.PersonalData = GetSelectListItemsDictionary();

            return View(model);
        }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        private EditUserViewModel GetEditUserViewModelFromApplicationUser(ApplicationUser user)
        {
            EditUserViewModel model = new EditUserViewModel
            {
                Id = user.Id,
                Number = user.Number,
                Status = user.Status,
                Email = user.Email,
                EmailConfirmed = user.EmailConfirmed,
                Age = user.Age,
                CreationDate = user.CreationDate,
                LastLoginTime = user.LastLoginTime,
                OpenPassword = user.OpenPassword,
                Notes = user.Notes,

                FirstName = user.FirstName,
                LastName = user.LastName,
                NameInRoman = user.NameInRoman,
                Birthday = user.Birthday,
                Location = user.Location.Id,
                Religion = user.Religion.Id,
                Activity = user.Activity.Id,
                Job = user.Job.Id,
                Education = user.Education.Id,
                FirstLanguage = user.FirstLanguage.Id,
                FirstLanguageLevel = user.FirstLanguageLevel.Id,
                SecondLanguage = user.SecondLanguage.Id,
                SecondLanguageLevel = user.SecondLanguageLevel.Id,
                ThirdLanguage = user.ThirdLanguage.Id,
                ThirdLanguageLevel = user.ThirdLanguageLevel.Id,
                Relationship = user.Relationship.Id,
                NumberOfChildren = user.NumberOfChildren.Id,
                Height = user.Height,
                Weight = user.Weight,
                Shape = user.Shape.Id,
                EyeColor = user.EyeColor.Id,
                HairColor = user.HairColor.Id,
                Smoking = user.Smoking.Id,
                Alcohol = user.Alcohol.Id,
                DesiredAge = user.DesiredAge.Id,
                Hobby = user.Hobby.Id,
                Lifestyle = user.Lifestyle.Id,
                Knowledge = user.Knowledge.Id,
                PhoneNumber = user.PhoneNumber,
                Skype = user.Skype,
                Facebook = user.Facebook,
                Vk = user.Vk,
                Twitter = user.Twitter,
                InternationalPassport = user.InternationalPassport.Id,
                FilePaths = user.FilePaths
            };

            return model;
        }