public void Update() { var user = default(User); try { user = new User(new UserEntity()); user.Attributes.Add(new UserAttributeEntity() { ItemID = 99, }); user.Create(); var item = new UserAttributeEntity() { ItemID = 199, Value = @"Item : 199", }; user.Attributes.Add(item); user.Update(); user.Attributes.Remove(item); user.Update(); user.Find(); Assert.Equal(1, user.Attributes.Count); } finally { if (user != null) { user.Delete(); } } }
public async Task <Result> Update(string userId, long attributeId, UpdateUserAttributeModel updateUserAttribute) { ValidationResult validationResult = _updateUserAttribute.Validate(updateUserAttribute); if (!validationResult.IsValid) { _logger.LogWarning($"Invalid {typeof(UpdateUserAttributeModel).CustomAttributes} model"); return(Result.Fail(validationResult.Errors)); } BaseSpecification <UserAttributeEntity> baseSpecification = new BaseSpecification <UserAttributeEntity>(); baseSpecification.AddFilter(x => x.Id == attributeId); baseSpecification.AddFilter(x => x.UserId == userId); UserAttributeEntity userAttribute = await _userAttributeRepository.SingleOrDefault(baseSpecification); if (userAttribute == null) { _logger.LogError($"No UserAttribute. UserId {userId}, AttributeId {attributeId}"); return(Result.Fail("no_user_attribute", "No UserAttribute")); } userAttribute.Value = updateUserAttribute.Value; bool updateResult = await _userAttributeRepository.Update(userAttribute); if (!updateResult) { _logger.LogError($"Failed to update UserAttribute. UserId {userId}, AttributeId {attributeId}"); return(Result.Fail("failed_to_update_user_attribute", "Failed to update user attribute")); } return(Result.Ok()); }
public async Task <Result> Remove(string userId, long attributeId) { BaseSpecification <UserAttributeEntity> baseSpecification = new BaseSpecification <UserAttributeEntity>(); baseSpecification.AddFilter(x => x.Id == attributeId); baseSpecification.AddFilter(x => x.UserId == userId); UserAttributeEntity userAttribute = await _userAttributeRepository.SingleOrDefault(baseSpecification); if (userAttribute == null) { _logger.LogError($"No UserAttribute. UserId {userId}, AttributeId {attributeId}"); return(Result.Fail("no_user_attribute", "No UserAttribute")); } bool removeResult = await _userAttributeRepository.Remove(userAttribute); if (!removeResult) { _logger.LogError($"Failed to remove user attribute. UserId {userId}, AttributeId {attributeId}"); return(Result.Fail("failed_to_remove_user_attribute", "Failed to remove user attribute")); } return(Result.Ok()); }
public static DbDataReader Select(UserAttributeEntity entity, DbConnection connection, DbTransaction transaction) { var reader = KandaTableDataGateway._factory.CreateReader(connection, transaction); reader.CommandText = @"usp_SelectUserAttributes"; KandaDbDataMapper.MapToParameters(reader, entity); reader.ExecuteReader(); return(reader); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="connection"></param> /// <param name="transaction"></param> /// <returns></returns> public bool Register(UserAttributeEntity entity, DbConnection connection, DbTransaction transaction) { if (UserAttributesGateway.Update(entity, connection, transaction) == 1) { return(true); } if (UserAttributesGateway.Insert(entity, connection, transaction) == 1) { return(true); } return(false); }
public async Task <Result> Add(string userId, AddUserAttributeModel addUserAttribute) { ValidationResult validationResult = _addUserAttributeValidator.Validate(addUserAttribute); if (!validationResult.IsValid) { _logger.LogWarning($"Invalid {typeof(AddUserAttributeModel).Name} model"); return(Result.Fail(validationResult.Errors)); } BaseSpecification <AppUserEntity> userSpecification = new BaseSpecification <AppUserEntity>(); userSpecification.AddFilter(x => x.Id == userId); bool userExist = await _userRepository.Exist(userSpecification); if (!userExist) { _logger.LogError($"No User. UserId {userId}"); return(Result.Fail("no_user", "No User")); } BaseSpecification <UserAttributeEntity> keyAlreadyExistsSpecification = new BaseSpecification <UserAttributeEntity>(); keyAlreadyExistsSpecification.AddFilter(x => x.UserId == userId); keyAlreadyExistsSpecification.AddFilter(x => x.Key == addUserAttribute.Key); bool keyAlreadyExists = await _userAttributeRepository.Exist(keyAlreadyExistsSpecification); if (keyAlreadyExists) { _logger.LogError($"Key already exists. UserId {userId}, Key {addUserAttribute.Key}"); return(Result.Fail("key_already_exists", "Key already exists")); } UserAttributeEntity userAttribute = new UserAttributeEntity( key: addUserAttribute.Key, value: addUserAttribute.Value, userId: userId); bool addAttributeResult = await _userAttributeRepository.Add(userAttribute); if (!addAttributeResult) { _logger.LogError($"Failed to add user attribute. UserId {userId}"); return(Result.Fail("failed_to_add_user_attribute", "Failed to add user attribute")); } return(Result.Ok(userAttribute)); }
public static int Update(UserAttributeEntity entity, DbConnection connection, DbTransaction transaction) { var command = KandaTableDataGateway._factory.CreateCommand(connection, transaction); command.CommandText = @"usp_UpdateUserAttributes"; KandaDbDataMapper.MapToParameters(command, entity); var result = KandaTableDataGateway._factory.CreateParameter(KandaTableDataGateway.RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue, DBNull.Value); command.Parameters.Add(result); command.ExecuteNonQuery(); return((int)result.Value); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="connection"></param> /// <param name="transaction"></param> /// <returns></returns> public bool Update(UserAttributeEntity entity, DbConnection connection, DbTransaction transaction) { var updated = UserAttributesGateway.Update(entity, connection, transaction); return(updated == 1); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="connection"></param> /// <param name="transaction"></param> /// <returns></returns> public bool Create(UserAttributeEntity entity, DbConnection connection, DbTransaction transaction) { var created = UserAttributesGateway.Insert(entity, connection, transaction); return(created == 1); }