Ejemplo n.º 1
0
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            var towns = this.towns
                .GetAll()
                .Where(t => t.Name != " Всички")
                .Select(t => new SelectListItem
                {
                    Text = t.Name,
                    Value = t.Id.ToString()
                })
                .ToList();

            this.ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess
                                             ? "Успешна смяна на парола."
                                             : message == ManageMessageId.SetPasswordSuccess
                                                   ? "Успешно създаване на парола."
                                                   : message == ManageMessageId.SetTwoFactorSuccess
                                                         ? "Your two-factor authentication provider has been set."
                                                         : message == ManageMessageId.Error
                                                               ? "Възникна грешка."
                                                               : message == ManageMessageId.AddPhoneSuccess
                                                                     ? "Вашият телефонен номер бе добавен."
                                                                     : message == ManageMessageId.RemovePhoneSuccess
                                                                           ? "Телефонния Ви номер е премахнат."
                                                                           : string.Empty;

            var userId = this.User.Identity.GetUserId();
            var model = new IndexViewModel
                            {
                                Towns = towns,
                                FirstName = this.manager.Users.FirstOrDefault(u => u.Id == userId).FirstName,
                                LastName = this.manager.Users.FirstOrDefault(u => u.Id == userId).LastName,
                                Email = await this.UserManager.GetEmailAsync(userId),
                                HasPassword = this.HasPassword(),
                                PhoneNumber = await this.UserManager.GetPhoneNumberAsync(userId),
                                TwoFactor = await this.UserManager.GetTwoFactorEnabledAsync(userId),
                                Logins = await this.UserManager.GetLoginsAsync(userId),
                                BrowserRemembered =
                                    await
                                    this.AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
                            };
            return this.View(model);
        }
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            this.ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess
                                             ? "Your password has been changed."
                                             : message == ManageMessageId.SetPasswordSuccess
                                                   ? "Your password has been set."
                                                   : message == ManageMessageId.SetTwoFactorSuccess
                                                         ? "Your two-factor authentication provider has been set."
                                                         : message == ManageMessageId.Error
                                                               ? "An error has occurred."
                                                               : message == ManageMessageId.AddPhoneSuccess
                                                                     ? "Your phone number was added."
                                                                     : message == ManageMessageId.RemovePhoneSuccess
                                                                           ? "Your phone number was removed."
                                                                           : string.Empty;

            var userId = this.User.Identity.GetUserId();
            var model = new IndexViewModel
                            {
                                HasPassword = this.HasPassword(),
                                PhoneNumber = await this.UserManager.GetPhoneNumberAsync(userId),
                                TwoFactor = await this.UserManager.GetTwoFactorEnabledAsync(userId),
                                Logins = await this.UserManager.GetLoginsAsync(userId),
                                BrowserRemembered =
                                    await
                                    this.AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
                            };
            return this.View(model);
        }
Ejemplo n.º 3
0
        public ActionResult Index(IndexViewModel user)
        {
            if (user != null && this.ModelState.IsValid)
            {
                var currentUserId = this.User.Identity.GetUserId();

                var userToUpdate = this.manager.FindById(currentUserId);

                userToUpdate.FirstName = user.FirstName;
                userToUpdate.LastName = user.LastName;
                userToUpdate.Email = user.Email;
                userToUpdate.UserName = user.Email;
                userToUpdate.PhoneNumber = user.PhoneNumber;
                userToUpdate.TownId = user.TownId;
                this.manager.Update(userToUpdate);

                return this.RedirectToAction("Index", "Manage");
            }

            return this.View(user);
        }