コード例 #1
0
        public OperationResult Update(UserUpdateDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            if (string.IsNullOrWhiteSpace(dto.FirstName))
            {
                return(new OperationResult
                {
                    Success = false,
                    Message = "First name is empty"
                });
            }

            if (dto.FirstName.Length > 200)
            {
                return(new OperationResult
                {
                    Success = false,
                    Message = "First name is too long"
                });
            }

            if (string.IsNullOrWhiteSpace(dto.LastName))
            {
                return(new OperationResult
                {
                    Success = false,
                    Message = "Last name is empty"
                });
            }

            if (dto.LastName.Length > 200)
            {
                return(new OperationResult
                {
                    Success = false,
                    Message = "Last name is too long"
                });
            }

            var entity = _repository.GetById(dto.Id);

            if (entity == null)
            {
                return(new OperationResult
                {
                    Success = false,
                    Message = "User is not found"
                });
            }

            entity.BirthDate = dto.BirthDate;
            entity.FirstName = dto.FirstName;
            entity.LastName  = dto.LastName;

            _repository.Update(entity);
            return(new OperationResult
            {
                Success = true
            });
        }
コード例 #2
0
        public int Update(User user)
        {
            _userRepository.Update(user);

            return(_userRepository.SaveChanges());
        }