public ActionResult GetByComment(Guid commentId, [FromBody] NullableGuidDeserializer nullableUserId = null) { Guid?userId = nullableUserId.Property; Comment record; try { record = db.FindRecordById <Comment>(COMMENT_TABLE, commentId); } catch (Exception e) { Failure failure = FailureFact.Default(e, userId); db.InsertRecord(FAILURE_TABLE, failure); return(StatusCode(500, failure)); } if (record == null) { Failure failure = FailureFact.IdNotFound(null, userId, commentId); db.InsertRecord(FAILURE_TABLE, failure); return(NotFound(failure)); } Success success = SuccessFact.CommentRetrieved(commentId, userId); db.InsertRecord(SUCCESS_TABLE, success); return(new OkObjectResult(record)); }
public IActionResult Get(Guid reviewId, [FromBody] NullableGuidDeserializer nullableUserId = null) { Guid?userId = nullableUserId.Property; Review record; try { record = db.FindRecordById <Review>(REVIEW_TABLE, reviewId); } catch (Exception e) { Failure failure = FailureFact.Default(e, userId); db.InsertRecordAsync(FAILURE_TABLE, failure); return(StatusCode(500, failure)); } if (record == null) { Failure failure = FailureFact.IdNotFound(null, userId, reviewId); db.InsertRecordAsync(FAILURE_TABLE, failure); return(NotFound(failure)); } Success success = SuccessFact.ReviewRetrieved(reviewId, userId); db.InsertRecordAsync(SUCCESS_TABLE, success); return(new OkObjectResult(record)); }
public ActionResult GetByReview(Guid reviewId, [FromBody] NullableGuidDeserializer nullableUserId = null) { Guid?userId = nullableUserId.Property; List <Comment> records; List <Filter> filters = ParseQuery.ParseFilters("ReivewId", reviewId.ToString()); try { records = db.LoadRecords <Comment>(COMMENT_TABLE, filters, null, null); } catch (Exception e) { Failure failure = FailureFact.Default(e, userId); db.InsertRecord(FAILURE_TABLE, failure); return(StatusCode(500, failure)); } if (records == null) { Failure failure = FailureFact.NoRecordsFound(null, userId, null, filters, null); db.InsertRecord(FAILURE_TABLE, failure); return(NotFound(failure)); } Success success = SuccessFact.CommentsByReviewRetrieved(reviewId, userId); db.InsertRecord(SUCCESS_TABLE, success); return(new OkObjectResult(records)); }
public IActionResult Get([FromQuery(Name = "sortDirection")] string sortDirection = "asc", [FromQuery(Name = "sortField")] string sortField = "Time", [FromQuery(Name = "filterFields")] string filterFields = null, [FromQuery(Name = "filterValues")] string filterValues = null, [FromQuery(Name = "pageNumber")] int pageNumber = 0, [FromQuery(Name = "pageItems")] int pageItems = 10, [FromBody] NullableGuidDeserializer nullableUserId = null) { Guid?userId = nullableUserId.Property; Sort sort = ParseQuery.ParseSort(sortDirection, sortField); Page page = ParseQuery.ParsePage(pageNumber, pageItems); List <Filter> filters; try { filters = ParseQuery.ParseFilters(filterFields, filterValues); } catch (Exception e) { Failure failure = FailureFact.UnevenFilters(e, userId, filterValues, filterFields); db.InsertRecordAsync(FAILURE_TABLE, failure); return(BadRequest(failure)); } List <Review> records; try { records = db.LoadRecords <Review>(REVIEW_TABLE, filters, sort, page); } catch (Exception e) { Failure failure = FailureFact.Default(e, userId); db.InsertRecordAsync(FAILURE_TABLE, failure); return(StatusCode(500, failure)); } if (records.Count == 0) { Failure failure = FailureFact.NoRecordsFound(null, userId, sort, filters, page); db.InsertRecordAsync(FAILURE_TABLE, failure); return(NotFound(failure)); } List <PartialReview> partialRecords = new List <PartialReview>(); foreach (Review record in records) { partialRecords.Add(record.ToPartialReview()); } Success success = SuccessFact.ReviewsRetrieved(userId, sort, filters, page); db.InsertRecordAsync(SUCCESS_TABLE, success); return(new OkObjectResult(partialRecords)); }