예제 #1
0
        public async Task <bool> UpdateUser(UpdateUserVm updatedUser)
        {
            _logger.LogInformation("Updating user with id: " + updatedUser.Id);
            var account = await _context.CustomerAccounts.Where(c => c.Id == updatedUser.Id && c.IsActive == true).FirstOrDefaultAsync();

            try
            {
                if (account != null)
                {
                    account.FirstName   = updatedUser.FirstName;
                    account.LastName    = updatedUser.LastName;
                    account.Address     = updatedUser.Address;
                    account.Postcode    = updatedUser.Postcode;
                    account.Email       = updatedUser.Email;
                    account.PhoneNumber = updatedUser.PhoneNumber;

                    await _context.SaveChangesAsync();
                }
                _logger.LogInformation("Successfully updated user with id: " + updatedUser.Id);
                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError("Exception when updating user with info: " + updatedUser + e + e.StackTrace);
            }
            return(false);
        }
예제 #2
0
        public async Task <UserVm> UpdateUser(int userId, UpdateUserVm model)
        {
            var updateUserDto = new UpdateUserDto
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Id        = userId
            };
            var file = model.Image;

            if (file != null)
            {
                var extension = "." + file.FileName.Split(".").LastOrDefault();
                if (string.IsNullOrEmpty(extension))
                {
                    extension = string.Empty;
                }
                var imagesDirectory = Path.Combine(_appEnvironment.ContentRootPath, _commonSettings.UserImagesFolder);
                if (!Directory.Exists(imagesDirectory))
                {
                    Directory.CreateDirectory(imagesDirectory);
                }
                updateUserDto.ImageLocalUrl = Path.Combine(imagesDirectory, $"{userId}{extension}");
                await using var fileStream  = new FileStream(updateUserDto.ImageLocalUrl, FileMode.Create);
                await file.CopyToAsync(fileStream);

                updateUserDto.ImageCode         = StringExtensions.GenerateUniqueRandomToken();
                updateUserDto.ImageThumbnailUrl = $"{_commonSettings.ApplicationUrl}/api/user/image/{updateUserDto.ImageCode}";
            }

            await _userRepository.UpdateUser(updateUserDto);

            return(await this.GetUserById(userId));
        }
예제 #3
0
        public ActionResult MemberUpate(UpdateUserVm item)
        {
            this.UpdateJpg.UserUpJpg(item.Photo[0]);
            item.id = UserVm.LoginUser.UserId;

            var item0 = this.Userver.ChatUpdate(item);

            this.Userver.Update(item0);

            return(RedirectToAction("Member"));
        }
예제 #4
0
        public async Task <IActionResult> Edit(UpdateUserVm model)
        {
            if (ModelState.IsValid)
            {
                await _userService.UpdateAsync(model);

                return(RedirectToAction(Index_Action));
            }

            return(View(model));
        }
예제 #5
0
        public async Task <IActionResult> Edit(int id)
        {
            var user = await _userService.GetByIdAsync(id);

            if (user is null)
            {
                return(NotFound());
            }

            return(View(UpdateUserVm.FormUser(user)));
        }
예제 #6
0
        public async Task <ActionResult> UpdateUserAsync(int userId, UpdateUserVm updateUserVm)
        {
            var user = await _usersRepository.ReadByIdAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }

            _mapper.Map(updateUserVm, user);

            await _usersRepository.UpdateAsync(user);

            return(NoContent());
        }
예제 #7
0
        public async Task UpdateUser_notCallSaveFile_ifPhotoIsNull()
        {
            var mock  = new Mock <IFileService>();
            var model = new UpdateUserVm
            {
                Id    = (await Context.Users.FirstAsync()).Id,
                Photo = null
            };

            var service = GetUserService(mock);

            await service.UpdateAsync(model);

            mock.Verify(m => m.SaveFile(It.IsAny <IFormFile>()), Times.Never);
        }
        public async Task <IActionResult> UpdateUser(UpdateUserVm updatedUser)
        {
            _logger.LogInformation("Updating user with id: " + updatedUser.Id);
            if (updatedUser == null)
            {
                _logger.LogError("Failed to update user due to invalid or no user information: " + updatedUser);
                throw new ArgumentException(nameof(updatedUser));
            }
            var success = await _accountsService.UpdateUser(updatedUser);

            if (success)
            {
                _logger.LogInformation("Successfully updated user with id: " + updatedUser.Id);
                return(Ok(true));
            }
            _logger.LogError("Failed to update user with information: " + updatedUser);
            return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
예제 #9
0
        public UpdateUserVm ChatUsre(UserTb item)
        {
            var item0 = new UpdateUserVm
            {
                Email = item.Email,

                Fullname = item.Name,

                NiName = item.Niname,

                Phone = item.Phone,

                Sex = 1,

                Bireday = item.UserText,
            };



            return(item0);
        }
예제 #10
0
        public UserTb ChatUpdate(UpdateUserVm item)
        {
            var item0 = this.Db.UserTb.FirstOrDefault(p => p.ID == item.id);
            var Exp0  = this.Db.Exp.FirstOrDefault(p => p.User_ID == item.id);
            var Iden0 = this.Db.Iden.FirstOrDefault(p => p.ID == item0.Iden_ID);

            item0.Email = item.Email;

            item0.Name = item.Fullname;

            item0.Niname = item.NiName;

            item0.Phone = item.Phone;

            item0.Sex = (Models.Src.Sex)item.Sex;

            item0.UserText = item.Bireday;



            return(item0);
        }
예제 #11
0
        public void Setup()
        {
            _mockAccountsService       = new Mock <IAccountsService>();
            _mockLogger                = new Mock <ILogger <AccountsController> >();
            _mockOrdersService         = new Mock <IOrdersService>();
            _accountsController        = new AccountsController(_mockAccountsService.Object, _mockOrdersService.Object, _mockLogger.Object);
            _stubCustomerAccountDetail = new CustomerAccountDetailVm
            {
                Id                = new Guid("58dfa3d3-83e3-490f-97f4-3290037ea365"),
                FirstName         = "Oliver",
                LastName          = "McHale",
                Address           = "Test Drive",
                Postcode          = "TS23 TST",
                DOB               = new DateTime(),
                IsActive          = true,
                CanPurchase       = true,
                LoggedOnAt        = new DateTime(),
                Email             = "*****@*****.**",
                PhoneNumber       = "01642652413",
                IsDeleteRequested = false
            };

            _stubCustomerAccountListItem = new CustomerAccountListItemVm
            {
                FirstName         = "Oliver",
                LastName          = "McHale",
                Address           = "Test Close",
                Email             = "*****@*****.**",
                IsDeleteRequested = false,
                Id = new Guid("58dfa3d3-83e3-490f-97f4-3290037ea364")
            };

            var stubListItems = new List <CustomerAccountListItemVm>();

            stubListItems.Add(_stubCustomerAccountListItem);

            _stubAccountList = new CustomerAccountListVm
            {
                CustomerAccounts = stubListItems
            };

            _stubEnableUpdatePurchaseAbilityVm = new UpdatePurchaseAbilityVm()
            {
                AccountId       = new Guid("58dfa3d3-83e3-490f-97f4-3290037ea364"),
                PurchaseAbility = true
            };
            _stubDisableUpdatePurchaseAbilityVm = new UpdatePurchaseAbilityVm()
            {
                AccountId       = new Guid("58dfa3d3-83e3-490f-97f4-3290037ea365"),
                PurchaseAbility = true
            };
            _stubUpdateUserVm = new UpdateUserVm()
            {
                Id          = new Guid("58dfa3d3-83e3-490f-97f4-3290037ea365"),
                Address     = "Test Avenue",
                Email       = "[email protected]@",
                FirstName   = "Unit",
                LastName    = "Test",
                PhoneNumber = "230954822412",
                Postcode    = "T3ST 101"
            };
            _stubCustomerAccountDto = new CustomerAccountDto
            {
                Id                = new Guid("58dfa3d3-83e3-490f-97f4-3290037ea365"),
                FirstName         = "Oliver",
                LastName          = "McHale",
                Address           = "Test Drive",
                Postcode          = "TS23 TST",
                DOB               = new DateTime(),
                IsActive          = true,
                CanPurchase       = true,
                LoggedOnAt        = new DateTime(),
                Email             = "*****@*****.**",
                PhoneNumber       = "01642652413",
                IsDeleteRequested = false
            };
        }
예제 #12
0
 public async Task <IActionResult> UpdateUser([FromForm] UpdateUserVm model)
 {
     return(this.Ok(await _userService.UpdateUser(this.CurrentUserId.Value, model)));
 }
예제 #13
0
 public static async Task <ActionResult> UpdateUserAsync(this HttpClient client, int userId, UpdateUserVm updateUserVm, HttpStatusCode expectedStatusCode = HttpStatusCode.NoContent)
 {
     return(await client.DoPutAsync <UpdateUserVm, ActionResult>($"{url}/{userId}", updateUserVm, expectedStatusCode));
 }
예제 #14
0
        public async Task <IActionResult> Put([FromForm] UpdateUserVm model)
        {
            await _userService.UpdateAsync(model);

            return(Ok());
        }