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)); } }
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)); }
public void Test_GenerateOrderByFunc_InvalidKey() { var queryParams = new ReviewQueryParamsModel(); queryParams.SortKey = "missing"; var orderByFunc = ReviewRepository.GenerateOrderByFunc(queryParams); Assert.Null(orderByFunc); }
public void Test_GenerateOrderByFunc(string sortKey) { var queryParams = new ReviewQueryParamsModel(); queryParams.SortKey = sortKey; var orderByFunc = ReviewRepository.GenerateOrderByFunc(queryParams); Assert.NotNull(orderByFunc); }
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)); }
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); }
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)); } }
public async Task <IActionResult> Get([FromQuery] ReviewQueryParamsModel queryParams) { return(Ok(await _unitOfWork.Review.GetAsync(queryParams))); }