public async Task <ActionResult <Post> > CreatePost(PostForm postForm) { Post post = postForm.toPost(); var context = new ValidationContext(post, serviceProvider: null, items: null); var validationResults = new List <ValidationResult>(); bool isValid = Validator.TryValidateObject(post, context, validationResults, true); if (!isValid) { return(BadRequest()); } else { string ip = HttpContext.Connection.RemoteIpAddress.ToString(); string anonymousId = Crypt.ComputeSha256Hash(ip).Substring(0, 8); post.AnnoymousId = anonymousId; _context.Posts.Add(post); await _context.SaveChangesAsync(); post.HideColumnsByAuthLevel(); return(CreatedAtAction(nameof(GetPost), new { id = post.PostId }, post)); } }