コード例 #1
0
        public async Task <GetTaskResponse> GetTaskAsync(long id)
        {
            RedisProvider _redis = new RedisProvider();

            //todo convert to string to tostring
            var _key  = $"{Constants.TASK_PREFIX}{Convert.ToString(id)}";
            var _data = _redis.Get <ToDoTask>(_key);

            return(new GetTaskResponse
            {
                Payload = _data,
            });
        }
コード例 #2
0
        public async Task <ToDoTask> ChangeTaskStatusAsync(long id)
        {
            RedisProvider _redis = new RedisProvider();
            //todo rename with ctrl + R + R
            var _key  = $"{Constants.TASK_PREFIX}{Convert.ToString(id)}";
            var _data = _redis.Get <ToDoTask>(_key);

            _data.IsDone = !(_data.IsDone);

            _redis.Set(_key, _data);

            return(_data);
        }
コード例 #3
0
        public async Task <Cart> AddToCartAsync(long product, string userId)
        {
            Random random = new Random();

            var userCart = await _redisProvider.Get <Cart>(string.Format(Constants.USER_CART_INFO, userId));

            if (userCart == null)
            {
                userCart = new Cart
                {
                    Products = new List <Product>(),
                    Id       = random.Next(0, 1000)
                }
            }
            ;

            var currentProduct = await _product.GetAsync(product.ToString());

            userCart.Products.Add(currentProduct);
            await _redisProvider.Set(string.Format(Constants.USER_CART_INFO, userId), userCart, TimeSpan.FromDays(3));

            return(userCart);
        }