Ejemplo n.º 1
0
        public async Task <bool> Login(string username, string password)
        {
            using (var session = _cassandraDbConnectionProvider.Connect())
            {
                string cql  = "SELECT * FROM users WHERE username = ?";
                var    user = await _cassandraQueryProvider.QuerySingleOrDefault <User>(session, cql, username);

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

                if (!ValidatePassword(user, password))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Test(UserRegisterLoginDto user)
        {
            using (var session = _cassandraDbConnectionProvider.Connect())
            {
                try
                {
                    var result = await _authenticationService.Register(user.Username, user.Password);

                    return(Ok(result));
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        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);
            }
        }