// POST odata/UserElementField public async Task <IHttpActionResult> Post(Delta <UserElementField> patch) { var userElementField = patch.GetEntity(); // Don't allow the user to set these fields / coni2k - 29 Jul. '17 // TODO Use ForbiddenFieldsValidator?: Currently breeze doesn't allow to post custom (delta) entity // TODO Or use DTO?: Needs a different metadata than the context, which can be overkill //userElementField.UserId = 0; userElementField.CreatedOn = DateTime.UtcNow; userElementField.ModifiedOn = DateTime.UtcNow; userElementField.DeletedOn = null; // Owner check: Entity must belong to the current user // REMARK UserCommandTreeInterceptor already filters "userId" on EntityFramework level, but that might be removed later on / coni2k - 31 Jul. '17 var currentUserId = User.Identity.GetUserId <int>(); if (currentUserId != userElementField.UserId) { return(StatusCode(HttpStatusCode.Forbidden)); } await _projectManager.AddUserElementFieldAsync(userElementField); return(Created(userElementField)); }