Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(AccountEditViewModel accountEditViewModel)
        {
            //Populate available list of roles after form post cleared the list
            accountEditViewModel.AvailableIdentityRoles = await _userRepo.GetAllRoles();

            if (ModelState.IsValid)
            {
                var emailIsUnique = await _userRepo
                                    .CheckIfEmailIsUnique(accountEditViewModel.UserAccount.Email,
                                                          accountEditViewModel.UserAccount.Id);

                if (!emailIsUnique)
                {
                    ModelState.AddModelError(ModelStateErrorMsgKey, MsgDuplicateEmail);
                    return(View(accountEditViewModel));
                }

                var result = await _userRepo.UpdateUser(accountEditViewModel.UserAccount);

                if (result)
                {
                    return(RedirectToAction("Details",
                                            new { userName = accountEditViewModel.UserAccount.UserName }));
                }
            }

            ModelState.AddModelError(ModelStateErrorMsgKey, MsgUnexpectedError);
            return(View(accountEditViewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            Login login = _dataService.GetLoginById(id);
            AccountEditViewModel viewModel = login.ConvertToEditViewModel();

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(AccountEditViewModel vm)
        {
            RemoveNavigationPropertiesFromModelState <AccountEditViewModel>();
            if (ModelState.IsValid)
            {
                ViewHelpers.RemoveAllNavigationProperties(vm);

                if (string.IsNullOrEmpty(vm.Password))
                {
                    ModelState.AddModelError(nameof(AccountEditViewModel.Password), "A Password must be set");
                    return(View(vm));
                }

                if (!await IsCurrentUserSuperAdminAsync().ConfigureAwait(false))
                {
                    vm.IsAdmin      = false;
                    vm.IsSuperAdmin = false;
                }

                var result = await _mapper.CreateAccountAsync(vm).ConfigureAwait(false);

                if (!result.Succeeded)
                {
                    ModelState.AddModelError(string.Empty, result.Errors.First().Description);
                    return(View(vm));
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }
Ejemplo n.º 4
0
        public IHttpActionResult Edit(AccountEditViewModelItem request)
        {
            AccountEditViewModel viewmodel = new AccountEditViewModel();
            UserDataController   dataCtrl  = new UserDataController();

            try
            {
                User updateModel = dataCtrl.GetItem(request.ID);
                updateModel.ToModel(request);

                if (request.OldPassword != null && request.NewPassword1 != null && request.NewPassword2 != null)
                {
                    var newPassword = PasswordHelper.ChangePassword(dataCtrl.GetItem(UserHelper.CurrentUserID), request.OldPassword, request.NewPassword1, request.NewPassword2);
                    dataCtrl.ChangePassword(UserHelper.CurrentUserID, newPassword);
                    viewmodel.AddSuccessMessage("Passwort wurde geändert.");
                }

                updateModel = dataCtrl.Update(updateModel);
                viewmodel.Data.FromModel(updateModel);
            }
            catch (WrongPasswordException)
            {
                return(Warning(viewmodel, "Das eingegebene Passwort stimmt nicht."));
            }
            catch (PasswordsNotEqualException)
            {
                return(Warning(viewmodel, "Die eingegebenen Passwörter stimmt nicht überein."));
            }
            catch (Exception ex)
            {
                return(Error(viewmodel, ex));
            }

            return(Ok(viewmodel, "Profil wurde aktualisiert."));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(AccountEditViewModel viewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View("Edit", viewModel));
            }

            var user = await this.GetAuthenticatedUser();

            if (!string.Equals(viewModel.UserName, user.UserName, StringComparison.OrdinalIgnoreCase))
            {
                var isUserNameAlreadyUsed = await this.Repository.IsUserNameAlreadyUsed(viewModel.UserName);

                if (isUserNameAlreadyUsed)
                {
                    this.ModelState.AddModelError <AccountEditViewModel>(vm => vm.UserName, "This username is already used");
                    return(this.View("Edit", viewModel));
                }
            }

            user.UserName = viewModel.UserName;
            await this.Repository.UpdateUser(user);

            return(this.RedirectToAction("Index", "Account"));
        }
Ejemplo n.º 6
0
        public ActionResult Edit(AccountEditViewModel model)
        {
            ApplicationUser user = UserManager.FindByEmail(User.Identity.Name);

            if (user != null)
            {
                user.FirstName  = model.FirstName;
                user.LastName   = model.LastName;
                user.MiddleName = model.MiddleName;
                if (model.Birth != Convert.ToDateTime("01.01.0001 0:00:00"))
                {
                    user.Birth = model.Birth;
                }
                user.PhoneNumber = model.PhoneNumber;
                user.Address     = model.Address;
                IdentityResult result = UserManager.Update(user);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Что-то пошло не так");
                }
            }
            else
            {
                ModelState.AddModelError("", "Пользователь не найден");
            }

            return(View(model));
        }
Ejemplo n.º 7
0
        public PartialViewResult EditAccount()
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);
            var banks  = new List <Bank>();
            var Banks  = db.Banks.Where(b => b.HouseholdId == user.HouseholdId).ToList();

            foreach (var Bank in Banks)
            {
                banks.Add(Bank);
            }
            var accountType  = new List <AccountType>();
            var AccountTypes = db.AccountTypes.ToList();

            foreach (var Item in AccountTypes)
            {
                accountType.Add(Item);
            }

            var EditAccount = new AccountEditViewModel
            {
                Banks       = banks,
                AccountType = accountType
            };

            ViewBag.Banks       = new SelectList(banks, "Id", "Name");
            ViewBag.AccountType = new SelectList(accountType, "Id", "Type");


            return(PartialView("~/Views/Shared/_EditAccount.cshtml", EditAccount));
        }
Ejemplo n.º 8
0
        public ActionResult _Edit(AccountEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            var account = AccountBL.Get(model.ID, base._DB);

            if (account.Password != model.ExPassword)
            {
                throw new BusinessException("Eski şifrenizi kontrol ederek tekrar deneyiniz.");
            }

            var mapper = new AccountMapper();

            var accountDTO = mapper.MapToDTO(model);

            AccountBL.Update(accountDTO.ID, accountDTO, base._DB);

            return(new ContentResult()
            {
                Content = "OK"
            });
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create(AccountEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId = GetCurrentUserId();

            var account = new Account
            {
                Id         = Guid.NewGuid(),
                UserId     = Guid.Parse(userId),
                CreatedOn  = DateTime.Now,
                Balance    = 0,
                Name       = string.IsNullOrEmpty(model.Name) ? "Account" : model.Name,
                StatusId   = 1,
                CurrencyId = model.CurrencyNumber,
                Cards      = new List <Card>()
            };

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            await _accountService.CreateAccountAsync(account, user.FullName, user.PhoneNumber, model.CardName);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Register([FromBody] AccountEditViewModel data)
        {
            // check existed user
            var existedUsername = await userManager.FindByNameAsync(data.UserName);

            if (existedUsername != null)
            {
                return(Ok(new { message = "Username da ton tai" }));
            }


            var user = new ApplicationUser();

            mapper.Map(data, user);
            user.SecurityStamp = Guid.NewGuid().ToString();
            user.UserName      = data.UserName;

            if (data.Password != data.ConfirmPassword)
            {
                return(BadRequest(new { message = "Xác thực password ko khớp" }));
            }

            var result = await userManager.CreateAsync(user, data.Password);

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(user, data.RoleId);
            }
            return(Ok(new { message = "register thanh cong" }));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Edit(string id, AccountEditViewModel model)
        {
            var agent = _userManager.FindByIdAsync(id).Result;

            agent.FirstName = model.FirstName;
            agent.LastName  = model.LastName;
            agent.Email     = model.Email;
            agent.Office    = model.Office;

            if (model.Password != null)
            {
                var removePassword = await _userManager.RemovePasswordAsync(agent);

                if (removePassword.Succeeded)
                {
                    var AddPassword = await _userManager.AddPasswordAsync(agent, model.Password);

                    if (AddPassword.Succeeded)
                    {
                        return(Redirect("/Account/Agents"));
                    }
                }
            }
            _repo.SaveChanges();

            return(Redirect("/Account/Agents"));
        }
        public IActionResult Details(int id)
        {
            User user = GetUserById(id);

            AccountEditViewModel eDet = user.CopyTo <AccountEditViewModel>();

            return(View(eDet));
        }
Ejemplo n.º 13
0
 public GreetingViewModel(
     AccountService accountService,
     AccountEditViewModel accountEditVM,
     IWindowManager windowManager)
 {
     _accountService = accountService;
     _accountEditVM  = accountEditVM;
     _windowManager  = windowManager;
 }
        public IActionResult Details(AccountEditViewModel eDet)
        {
            if (!ModelState.IsValid)
            {
                return(View(eDet));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 15
0
 public AccountEditView()
 {
     InitializeComponent();
     _CurrenciesShortcuts = getAllCurrenciesShortcuts();
     _CurrenciesNames     = getAllCurrenciesNames();
     fillCurrencies();
     _accountEntityValidator = Program.Factory.Resolve <IEntityValidator>();
     _accountEditViewModel   = Program.Factory.Resolve <AccountEditViewModel>();
     TranslateControls();
 }
Ejemplo n.º 16
0
        public async Task <IActionResult> Create()
        {
            var model = new AccountEditViewModel
            {
                Currencies   = (List <CountryCurrencyCode>) await _countryCurrencyCodeService.GetCurrenciesAsync(),
                Departaments = (List <Departament>) await _departamentService.GetDepartamentsAsync()
            };

            return(View(model));
        }
Ejemplo n.º 17
0
        public ActionResult Edit(AccountEditViewModel accountEditViewModel, HttpPostedFileBase profileImage)
        {
            ServiserDbContext db = new ServiserDbContext();
            User user            = User.Identity.GetUser(true);

            if (user.Id == accountEditViewModel.UserId)
            {
                user.FirstName   = accountEditViewModel.FirstName;
                user.LastName    = accountEditViewModel.LastName;
                user.Email       = accountEditViewModel.Email;
                user.PhoneNumber = accountEditViewModel.PhoneNumber;
                user.UserName    = accountEditViewModel.Email;
            }
            if (user.MechanicProfile != null && user.MechanicProfile.Id == accountEditViewModel.MechanicProfileId)
            {
                user.MechanicProfile.CNIC = accountEditViewModel.CNIC;
            }
            if (user.CustomerProfile != null && user.CustomerProfile.Id == accountEditViewModel.CustomerProfileId)
            {
            }


            if (profileImage.ContentLength > 0)
            {
                string remoteDirectoryPath = "~/Data_Files/UserProfileImages/";

                string remoteFilePath = remoteDirectoryPath +
                                        Guid.NewGuid().ToString() +
                                        Path.GetFileName(profileImage.FileName);

                string localPath = Server.MapPath(remoteFilePath);

                Directory.CreateDirectory(Server.MapPath(remoteDirectoryPath));

                profileImage.SaveAs(localPath);

                if (user.ProfileImageUrl != null && !String.IsNullOrWhiteSpace(user.ProfileImageUrl))
                {
                    string localFilePath = Server.MapPath(user.ProfileImageUrl);
                    if (System.IO.File.Exists(localFilePath))
                    {
                        System.IO.File.Delete(localFilePath);
                        user.ProfileImageUrl = null;
                    }
                }

                user.ProfileImageUrl = remoteFilePath;
            }

            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 18
0
 public AccountDTO MapToDTO(AccountEditViewModel vm)
 {
     return(new AccountDTO()
     {
         ID = vm.ID,
         FullName = vm.FullName,
         Email = vm.Email,
         Password = vm.Password,
         RoleName = vm.RoleName
     });
 }
Ejemplo n.º 19
0
        public ActionResult Edit([Bind(Include = "Id,Login,Phone,Email,Password")] AccountEditViewModel accountEditViewModel)
        {
            if (ModelState.IsValid)
            {
                accountEditViewModel.Password = _encrypter.HashPassword(accountEditViewModel.Password);
                var account = _mapper.Map <Account>(accountEditViewModel);

                _repositoryAccount.Update(account);
                return(RedirectToAction("Index"));
            }
            return(View(accountEditViewModel));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Edit()
        {
            var user = await this.userManager.GetUserAsync(this.User);

            AccountEditViewModel model = new AccountEditViewModel()
            {
                UserName = user.UserName,
                Email    = user.Email
            };

            return(View(model));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Create(AccountEditViewModel model)
        {
            if (_accountService.Exist(model.Username))
            {
                ModelState.AddModelError("username", $"User '{model.Username}' already exist.");
                return(Conflict(ModelState));
            }

            await _accountService.CreateAsync(model.Username, model.Password);

            return(Ok());
        }
Ejemplo n.º 22
0
        public LaunchViewModel(
            ConfigService configService,
            ThemeService themeService,
            VersionService versionService,
            LibraryService libraryService,
            AssetService assetService,
            AccountService accountService,
            AuthService authService,
            AuthlibInjectorService authlibInjectorService,
            LaunchService launchService,
            DownloadService downloadService,
            LogService logService,

            IWindowManager windowManager,
            GreetingViewModel greetingVM,
            VersionsManagementViewModel versionsVM,
            LaunchStatusViewModel statusVM,
            AccountEditViewModel accountEditVM,
            DownloadStatusViewModel downloadVM,
            ErrorReportViewModel errorReportVM,
            ProfileSelectViewModel profileSelectVM)
        {
            _windowManager = windowManager;
            _config        = configService.Entries;

            _versionService         = versionService;
            _libraryService         = libraryService;
            _assetService           = assetService;
            _accountService         = accountService;
            _authService            = authService;
            _authlibInjectorService = authlibInjectorService;
            _launchService          = launchService;
            _downloadService        = downloadService;
            _logService             = logService;

            _statusVM         = statusVM;
            _accountEditVM    = accountEditVM;
            _profileSelectVM  = profileSelectVM;
            _downloadStatusVM = downloadVM;
            _errorReportVM    = errorReportVM;

            _launchService.Exited += OnGameExited;

            _versionService.Loaded  += hasAny => HasVersion = hasAny;
            _versionService.Created += _ => HasVersion = true;

            _statusVM.Closed += (sender, e) => OnLaunchCompleted();

            ThemeService = themeService;
            GreetingVM   = greetingVM;
            VersionsVM   = versionsVM;
        }
Ejemplo n.º 23
0
        public async Task <AccountEditViewModel> GetEditAccount(string id)
        {
            var user = await _userManager.FindByIdAsync(id);

            var roles = await _userManager.GetRolesAsync(user);

            AccountEditViewModel vm = new AccountEditViewModel()
            {
                Account = user, Roles = GetItemsRole()
            };

            return(vm);
        }
        public void NotSaveToDatabaseWithModelError()
        {
            _mockAcctRepo.Setup(x => x.GetById(It.IsAny <int>())).Returns(_acct1);

            var model = new AccountEditViewModel();

            _sut = new AccountsController(_mockAcctRepo.Object);

            _sut.ViewData.ModelState.AddModelError("x", "Test Error");

            _sut.EditAccount(1, model);

            _mockAcctRepo.Verify(x => x.Commit(), Times.Never);
        }
        public void TestAccountEditViewModelOK()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var currencyService = new CurrencyService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                Currency primaryCurrency = currencyService.GetPrimary();
                var      account         = new Account
                {
                    Name     = "My First Account",
                    Type     = AccountType.Asset,
                    SubType  = AccountSubType.Checking,
                    Currency = primaryCurrency,
                };
                accountService.Create(account);

                var viewModel = new AccountEditViewModel(
                    loggerFactory,
                    accountService,
                    currencyService,
                    account.AccountId
                    );

                viewModel.Name = "Updated Account";
                viewModel.SelectedAccountType    = AccountType.Liability;
                viewModel.SelectedAccountSubType = AccountSubType.CreditCard;
                viewModel.OKCommand.Execute(this);

                List <Account> accounts = accountService.GetAll().ToList();

                Assert.AreEqual(1, accounts.Count);
                Assert.AreEqual(viewModel.Name, accounts[0].Name);
                Assert.AreEqual(viewModel.SelectedAccountType, accounts[0].Type);
                Assert.AreEqual(viewModel.SelectedAccountSubType, accounts[0].SubType);
                Assert.AreEqual(account.Currency.CurrencyId, accounts[0].Currency.CurrencyId);
            }
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Information()
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = await _userManager.FindByIdAsync(userId);

            var userViewModel = new AccountEditViewModel
            {
                Name           = user.Name,
                ProfilePicLink = user.ProfilePicLink,
                FavBook        = _accountService.GetUserFavBook(user.FavBookId),
                UserAddresses  = _accountService.GetUserAddresses(userId)
            };

            return(View(userViewModel));
        }
Ejemplo n.º 27
0
        public async Task <ActionResult> UpdateProfile([FromBody] AccountEditViewModel data)
        {
            ClaimsPrincipal claims = this.User;
            var             userId = claims.FindFirst(ClaimTypes.NameIdentifier).Value;

            var currentUser = await userManager.FindByIdAsync(userId);

            mapper.Map(data, currentUser);
            await userManager.UpdateAsync(currentUser);

            return(Ok(new
            {
                message = $"Ban da update thanh cong User co ten la: {currentUser.UserName}"
            }));
        }
Ejemplo n.º 28
0
        // GET: Accounts/Edit/5
        public async Task <IActionResult> Edit(string id)
        {
            var isAuthorized = await _authorizationService.AuthorizeAsync(User, new AppUser { Id = id }, UserOperations.Read);

            if (isAuthorized.Succeeded)
            {
                AccountEditViewModel vm = await _accountService.GetEditAccount(id);

                return(View(vm));
            }
            else
            {
                return(new ChallengeResult());
            }
        }
Ejemplo n.º 29
0
        public IHttpActionResult Edit()
        {
            AccountEditViewModel viewmodel = new AccountEditViewModel();
            UserDataController   dataCtrl  = new UserDataController();

            try
            {
                viewmodel.Data.FromModel(dataCtrl.GetItem(UserHelper.CurrentUserID));
            }
            catch (Exception ex)
            {
                return(Error(viewmodel, ex));
            }

            return(Ok(viewmodel));
        }
 public ActionResult Edit(AccountEditViewModel accountEditViewModel)
 {
     if (ModelState.IsValid)
     {
         Account account = new Account()
         {
             Email    = accountEditViewModel.Email,
             Id       = accountEditViewModel.Id,
             Phone    = accountEditViewModel.Phone,
             Password = accountEditViewModel.Password
         };
         _repository.Update(account);
         return(RedirectToAction("Index"));
     }
     return(View(accountEditViewModel));
 }