Exemple #1
0
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            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 user = this.UserManager.FindById(userId);

            var model = new IndexViewModel
            {
                UserId = 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),
                ScienceDegree = user.ScienceDegree,
            };

            if (this.UserManager.IsInRole(model.UserId, GlobalConstants.StudentRoleName))
            {
                var student = this.students.GetByUserId(model.UserId).Include(s => s.SelectedDiploma).FirstOrDefault();

                if (student.SelectedDiploma != null)
                {
                    model.DiplomaId = student.SelectedDiploma.Id;
                    this.TempData["HasDiploma"] = true;
                }

                model.Address = student.Address;
                model.FNumber = student.FNumber;
                model.IsStudent = true;
                this.TempData["Student"] = true;
            }
            else
            {
                model.IsStudent = false;
            }

            return this.View(model);
        }
Exemple #2
0
        public ActionResult SaveInfo(IndexViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = this.UserManager.FindById(model.UserId);

                user.PhoneNumber = model.PhoneNumber;
                user.ScienceDegree = model.ScienceDegree;
                this.UserManager.Update(user);

                var student = this.students.GetByUserId(model.UserId).Where(s => !s.IsDeleted).FirstOrDefault();
                if (student != null)
                {
                    user.Student = student;
                    user.Student.FNumber = model.FNumber;
                    user.Student.Address = model.Address;
                    this.students.Save();
                }

                return this.RedirectToAction("Index", "Home", null);
            }

            return this.View("Index", model);
        }