public async Task <bool> Register(string username, string password) { GeneratePassword(password, out byte[] passwordHash, out byte[] passwordSalt); using (var session = _cassandraDbConnectionProvider.Connect()) { string cql = "INSERT INTO users (username, passwordhash, passwordsalt) VALUES (?, ?, ?)"; var newUser = await _cassandraQueryProvider.ExecuteAsync(session, cql, username, passwordHash, passwordSalt); if (newUser == null) { return(false); } } return(true); }
public async Task <bool> AddPromotion(AddPromotionDto addPromotionDto) { using (var session = _cassandraDbConnectionProvider.Connect()) { var preparedModifierStatement = await session.PrepareAsync("INSERT INTO modifiers (id, type, values) VALUES (?, ?, ?);"); Dictionary <Guid, string> modifierWithType = new Dictionary <Guid, string>(); foreach (var mod in addPromotionDto.Modifiers) { Guid id = Guid.NewGuid(); modifierWithType.Add(id, mod.Type); var boundModifierStatement = preparedModifierStatement.Bind(id, mod.Type, mod.Values); await _cassandraQueryProvider.ExecuteAsync(session, boundModifierStatement); } var preparedActionStatement = await session.PrepareAsync("INSERT INTO actions (id, type, flat, percentage, freeship, items) VALUES (?, ?, ?, ?, ?, ?);"); Dictionary <Guid, string> actionsWithType = new Dictionary <Guid, string>(); foreach (var action in addPromotionDto.Actions) { Guid id = Guid.NewGuid(); actionsWithType.Add(id, action.Type); var boundActionStatement = preparedActionStatement.Bind(id, action.Type, action.Flat, action.Percentage, action.FreeShip, action.Items); await _cassandraQueryProvider.ExecuteAsync(session, boundActionStatement); } Guid promoId = Guid.NewGuid(); string cql = "INSERT INTO promotions (id, type, description, modifiers, actions) VALUES (?, ?, ?, ?, ?);"; await _cassandraQueryProvider.ExecuteAsync(session, cql, promoId, addPromotionDto.Type, addPromotionDto.Description, modifierWithType, actionsWithType); return(true); } }