コード例 #1
0
        public ActionResult UpdateUser(Guid userId, UsersUpdateDto usersUpdate)
        {
            if (!_usersRepository.UserExists(userId).Result)
            {
                return(NotFound());
            }

            var result = _usersRepository.UpdateUser(userId, usersUpdate).Result;

            return(NoContent());
        }
コード例 #2
0
        public void UpdateUser(UsersUpdateDto model)
        {
            var userFromDb = this.GetUserById(model.Id);

            userFromDb.FirstName    = model.Firstname;
            userFromDb.MiddleName   = model.MiddleName;
            userFromDb.LastName     = model.MiddleName;
            userFromDb.Email        = model.Email;
            userFromDb.Address      = model.Address;
            userFromDb.PhoneNumber  = model.PhoneNumber;
            userFromDb.ProfileImage = model.ProfileImage;
            this.db.Update(userFromDb);
        }
コード例 #3
0
        public ActionResult UpdateUser(int id, UsersUpdateDto usersUpdateDto)
        {
            var userModelFromRepo = _repository.GetUserById(id);

            if (userModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(usersUpdateDto, userModelFromRepo);

            _repository.UpdateUser(userModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
コード例 #4
0
        public async Task <ActionResult> UpdateCommand(int id, UsersUpdateDto usersUpdateDto)
        {
            var userToBeUpdated = await _userRepository.GetUserById(id);

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

            _mapper.Map(usersUpdateDto, userToBeUpdated);
            await _userRepository.UpdateUser(userToBeUpdated);

            return(NoContent());
        }
コード例 #5
0
        public IActionResult Update([FromBody] UsersUpdateDto parm)
        {
            var userSession = _tokenManager.GetSessionInfo();

            #region 更新用户信息
            //判断用户是否已经存在
            if (_usersService.Any(m => m.UserID == parm.UserID))
            {
                return(toResponse(StatusCodeType.Error, $"添加 {parm.UserID} 失败,该用户已存在,不能重复!"));
            }
            #endregion

            var response = _usersService.Update(m => m.UserID == parm.UserID, m => new Sys_Users
            {
                UserName     = parm.UserName,
                NickName     = parm.NickName,
                Email        = parm.Email,
                Sex          = parm.Sex,
                AvatarUrl    = parm.AvatarUrl,
                QQ           = parm.QQ,
                Phone        = parm.Phone,
                ProvinceID   = parm.ProvinceID,
                Province     = parm.Province,
                CityID       = parm.CityID,
                City         = parm.City,
                CountyID     = parm.CountyID,
                County       = parm.County,
                Address      = parm.Address,
                Remark       = parm.Remark,
                IdentityCard = parm.IdentityCard,
                Birthday     = parm.Birthday,
                Enabled      = parm.Enabled,
                OneSession   = parm.OneSession,
                UpdateID     = userSession.UserID,
                UpdateName   = userSession.UserName,
                UpdateTime   = DateTime.Now
            });

            #region 更新登录会话记录

            _tokenManager.RefreshSession(parm.UserID);

            #endregion


            return(toResponse(response));
        }
コード例 #6
0
        public async Task <UsersDto> UpdateUser(Guid userId, UsersUpdateDto usersUpdateDto)
        {
            return(await Task.Run(async() =>
            {
                if (usersUpdateDto == null)
                {
                    throw new ArgumentNullException(nameof(usersUpdateDto));
                }

                var user = await _context.Users.FirstOrDefaultAsync(c => c.Id == userId);

                if (user == null)
                {
                    throw new ArgumentNullException(nameof(user));
                }

                _mapper.Map(user, user);

                bool save = await Save();

                return _mapper.Map <UsersDto>(user);
            }));
        }