예제 #1
0
        public async Task <UserModel> GetUser(int id)
        {
            Cql cql = new($"SELECT * FROM {tableName} WHERE userid=?", id);

            return(await CassandraConnection.GetInstance().GetRecord <UserModel>(cql)
                   .ConfigureAwait(false));
        }
        /// <summary>
        /// Retrieve data for recommendation
        /// </summary>
        /// <param name="cql">Cql request</param>
        /// <returns>List of wines</returns>
        public static async Task <List <WineModel> > GetWineData(Cql cql, int limit)
        {
            var result = await CassandraConnection.GetInstance()
                         .GetByRequestData <WineModel>(cql);

            return(new List <WineModel>().CopyElements(result, limit));
        }
        public async Task <ActionResult <WineModel> > GetWine(int id)
        {
            Cql cql = new($"WHERE id=? allow filtering", id);

            return(await CassandraConnection.GetInstance().GetRecord <WineModel>(cql)
                   .ConfigureAwait(false));
        }
예제 #4
0
        public UserRepository()
        {
            const string getUserByName = "SELECT * FROM users WHERE username = :username";
            const string createUser    = "******";

            _cassandraConnection = CassandraConnection.GetInstance();
            _getUserByName       = _cassandraConnection.PreparedStatement(getUserByName);
            _createUser          = _cassandraConnection.PreparedStatement(createUser);
        }
예제 #5
0
        public BlogRepository()
        {
            const string getAllBlogs = "SELECT * FROM blogs";
            const string createBlog  = "INSERT INTO blogs (id, content, date, title, writer) VALUES (now(), :content, :date, :title, :writer)";

            _cassandraConnection = CassandraConnection.GetInstance();
            _userRepository      = new UserRepository();
            _getAllBlogs         = _cassandraConnection.PreparedStatement(getAllBlogs);
            _createBlog          = _cassandraConnection.PreparedStatement(createBlog);
        }
예제 #6
0
        public HttpResponseMessage Reset()
        {
            var connection = CassandraConnection.GetInstance();

            foreach (var table in connection.GetTables())
            {
                connection.ExecuteNonReader($"TRUNCATE TABLE {CassandraConnection.KeySpace}.{table}");
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #7
0
        /// <summary>
        /// Retrieve selected wines from DB by their IDs
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public static async Task <List <WineModel> > GetSelectedData(int[] ids)
        {
            List <WineModel> selectedWines = new List <WineModel>();

            foreach (int id in ids)
            {
                Cql cql = new("WHERE id=? allow filtering", id);
                selectedWines.Add(await CassandraConnection.GetInstance().GetRecord <WineModel>(cql));
            }

            return(selectedWines);
        }
        public async Task <IEnumerable <WineModel> > GetWines([FromQuery] int page)
        {
            int startIndex = _pageSize * (page - 1);

            Cql cql = new($"SELECT * FROM {_tableName} where id >= ? and id < ? allow filtering", startIndex, startIndex + _pageSize);

            var temp = await CassandraConnection.GetInstance().GetByRequestData <WineModel>(cql);

            List <WineModel> result = temp.ToList().OrderBy(wine => wine.Id).ToList();

            return(result);
        }
예제 #9
0
        public async Task UpdateUserInfo(int id, string name, string email)
        {
            Cql cql = new("WHERE userid=?", id);

            var user = await CassandraConnection.GetInstance().GetRecord <UserModel>(cql)
                       .ConfigureAwait(false);

            UserModel newUser = new UserModel {
                Email    = email,
                Name     = name,
                UserId   = user.UserId,
                Password = user.Password
            };

            await CassandraConnection.GetInstance().UpdateRecord(newUser)
            .ConfigureAwait(false);
        }
        public async Task <JsonResult> GetFilteredWinesByPage(string color, string wine_type, string country, string vintage, int page)
        {
            Cql cql = new(WineControllerHelper.GenerateFilterCql(_tableName, color, wine_type, country, vintage));

            var tempList = (await CassandraConnection.GetInstance().GetByRequestData <WineModel> (cql)).ToList();
            List <WineModel> sortedResult = tempList.OrderBy(a => a.Id).ToList();

            int startIndex = _pageSize * (page - 1);
            int endIndex   = startIndex + _pageSize;

            var pagedList    = new List <WineModel>();
            int loopEndIndex = endIndex > tempList.Count ? tempList.Count : endIndex;

            for (int i = startIndex; i < loopEndIndex; i++)
            {
                pagedList.Add(sortedResult[i]);
            }

            return(new JsonResult(new FilterResult()
            {
                WineList = pagedList,
                Count = tempList.Count
            }));
        }
        public async Task <int> GetNumberOfWines()
        {
            Cql cql = new($"select id from {_tableName}");

            return(await CassandraConnection.GetInstance().GetNumberOfRecords <WineModel>(cql));
        }
예제 #12
0
 public async Task DeleteUser(int id)
 {
     Cql cql = new("WHERE userid=?", id);
     await CassandraConnection.GetInstance().DeleteRecord <UserModel>(cql)
     .ConfigureAwait(false);
 }
예제 #13
0
 public async Task AddUser(UserModel user)
 {
     await CassandraConnection.GetInstance().AddRecord(user)
     .ConfigureAwait(false);
 }