/// <summary> /// Get an individual entity /// </summary> /// <param name="id"></param> /// <param name="parentid"></param> /// <returns>An individual entity</returns> /// <exception cref="EntityOperationException"></exception> /// <exception cref="EntityDoesNotExistException"></exception> /// <exception cref="UnauthorizedOperationException"></exception> /// <exception cref="EntityValidationException"></exception> protected virtual async Task <IActionResult> GetEntity <TViewModel>(string id, string parentid = "") where TViewModel : class, IViewModel <T, TViewModel>, new() { T entity = null; TViewModel entityView = new TViewModel(); Guid parentGuid = Guid.Empty; if (!string.IsNullOrEmpty(parentid)) { parentGuid = new Guid(parentid); } entity = readRepository.GetOne(new Guid(id), parentGuid); if (entity == null) { ModelState.AddModelError("GetData", "Record does not exist or you do not have authorized access."); return(BadRequest(ModelState)); } else { entityView = entityView.Map(entity); } string timeStamp = "\"" + Convert.ToBase64String(entity.Timestamp) + "\""; if (Request.Headers.ContainsKey("if-none-match")) { string etag = Request.Headers["if-none-match"]; if (!string.IsNullOrEmpty(etag) && etag.Equals(timeStamp, StringComparison.InvariantCultureIgnoreCase)) { return(StatusCode(304)); //not modified if ETag is same as current timestamp } } try { Response.Headers.Add("ETag", timeStamp); } catch { return(Ok(entityView)); } return(Ok(entityView)); }