Esempio n. 1
0
        public async ValueTask <IActionResult> EditUserAccountDetailsAsync(long userId)
        {
            User user = new User();
            UpdateUserAccountViewModel updateUserAccountViewModel = new UpdateUserAccountViewModel();

            List <UserGender>          userGenders          = new List <UserGender>();
            List <UserGenderViewModel> userGendersViewModel = new List <UserGenderViewModel>();

            List <UserTitle>          userTitles          = new List <UserTitle>();
            List <UserTitleViewModel> userTitlesViewModel = new List <UserTitleViewModel>();

            var task1 = this._userManagementService.GetAllUserGenderDetailsAsync();
            var task2 = this._userManagementService.GetAllUserTitleDetailsAsync();
            var task3 = this._userManagementService.GetUserAccountDetailsAsync(userId);

            await Task.WhenAll(task1.AsTask(), task2.AsTask(), task3.AsTask());

            userGenders = await task1;
            userTitles  = await task2;
            user        = await task3;

            userGendersViewModel = this._mapper.Map <List <UserGenderViewModel> >(userGenders);
            userTitlesViewModel  = this._mapper.Map <List <UserTitleViewModel> >(userTitles);

            updateUserAccountViewModel             = this._mapper.Map <UpdateUserAccountViewModel>(user);
            updateUserAccountViewModel.UserTitles  = userTitlesViewModel;
            updateUserAccountViewModel.UserGenders = userGendersViewModel;

            return(await Task.Run(() => this.View("EditUserAccountDetails", updateUserAccountViewModel)));
        }
        public async Task CanUpdateUserAccountDetailsAsync()
        {
            //Arrange
            this._userManagementService
            .Setup(m => m.UpdateUserAccountDetailsAsync(It.IsAny <User>()))
            .ReturnsAsync(true);

            this._userManagementController = new UserManagementController(
                this._mapper
                , this._appSetting.Object
                , this._userManagementService.Object
                );

            UpdateUserAccountViewModel updateUserAccountViewModel = new UpdateUserAccountViewModel();

            //Act
            var result = await this._userManagementController.UpdateUserAccountDetailsAsync(updateUserAccountViewModel);

            //Assert
            Assert.IsType <JsonResult>(result);

            var jsonResult = ((JsonResult)result).Value.ToString();
            var jsonResultDeserializeObject = JsonConvert.DeserializeObject <dynamic>(jsonResult);
            var jsonResultStatus            = jsonResultDeserializeObject.Status.Value;

            Assert.Equal(jsonResultStatus, "Success");
        }
Esempio n. 3
0
        public async ValueTask <IActionResult> UpdateUserAccountDetailsAsync(UpdateUserAccountViewModel updateUserAccountViewModel)
        {
            dynamic ajaxReturn = new JObject();
            User    user       = new User();
            var     userAuthenticationModel = WebAppMVCExtensions.GetLoggedInUserDetails(this.User);

            user            = this._mapper.Map <User>(updateUserAccountViewModel);
            user.ModifiedBy = userAuthenticationModel.UserId;

            var isUpdateSuccess = await this._userManagementService.UpdateUserAccountDetailsAsync(user);

            if (isUpdateSuccess)
            {
                ajaxReturn.Status  = "Success";
                ajaxReturn.Message = "User details saved successfully";
            }
            else
            {
                ajaxReturn.Status  = "Error";
                ajaxReturn.Message = "Error occured";
            }

            return(this.Json(ajaxReturn));
        }