コード例 #1
0
        public async Task <IActionResult> Post([FromQuery] ReviewQueryParamsModel queryParams, ReviewModel review)
        {
            if (review == null)
            {
                return(BadRequest());
            }

            var ExistingEntry = await _unitOfWork.Review.GetAsync(review.Id, queryParams);

            if (ExistingEntry == null)
            {
                var obj = await _unitOfWork.Review.InsertAsync(review);

                await _unitOfWork.CommitAsync();

                return(Ok(obj));
            }
            else
            {
                _unitOfWork.Review.Update(review);

                await _unitOfWork.CommitAsync();

                return(Ok(review));
            }
        }
コード例 #2
0
        public void Test_Trivial_NullableInt_Props(string propName)
        {
            var queryParams = new ReviewQueryParamsModel();
            var prop        = queryParams.GetType().GetProperty(propName);

            prop.SetValue(queryParams, 1);
            Assert.Equal(1, prop.GetValue(queryParams));
        }
コード例 #3
0
        public void Test_GenerateOrderByFunc_InvalidKey()
        {
            var queryParams = new ReviewQueryParamsModel();

            queryParams.SortKey = "missing";

            var orderByFunc = ReviewRepository.GenerateOrderByFunc(queryParams);

            Assert.Null(orderByFunc);
        }
コード例 #4
0
        public void Test_GenerateOrderByFunc(string sortKey)
        {
            var queryParams = new ReviewQueryParamsModel();

            queryParams.SortKey = sortKey;

            var orderByFunc = ReviewRepository.GenerateOrderByFunc(queryParams);

            Assert.NotNull(orderByFunc);
        }
コード例 #5
0
        public async Task <IActionResult> Get([FromQuery] ReviewQueryParamsModel queryParams, int id)
        {
            var obj = await _unitOfWork.Review.GetAsync(id, queryParams);

            if (obj == null)
            {
                return(NotFound());
            }
            return(Ok(obj));
        }
コード例 #6
0
        public void Test_GenerateFilterFuncs()
        {
            var queryParams = new ReviewQueryParamsModel();

            queryParams.AccountId = 1;
            queryParams.LodgingId = 1;

            var funcs = ReviewRepository.GenerateFilterFuncs(queryParams);

            // 1 filter is always added, +2 more based on params.
            Assert.Equal(3, funcs.Count);
        }
コード例 #7
0
        public void Test_Clamped_Props_Double(string propName, double min, double max)
        {
            var queryParams = new ReviewQueryParamsModel();
            var prop        = queryParams.GetType().GetProperty(propName);

            prop.SetValue(queryParams, -99999999);
            Assert.Equal(min, prop.GetValue(queryParams));

            if (min != max)
            {
                prop.SetValue(queryParams, 99999999);
                Assert.Equal(max, prop.GetValue(queryParams));
            }
        }
コード例 #8
0
 public async Task <IActionResult> Get([FromQuery] ReviewQueryParamsModel queryParams)
 {
     return(Ok(await _unitOfWork.Review.GetAsync(queryParams)));
 }