public async Task <IActionResult> PutPost(int id, CreateAndUpdateHttpPost postModel) { var post = postModel.Post; var imageBase64 = postModel.Uri; if (id != post.Id) { return(BadRequest()); } _context.Entry(post).State = EntityState.Modified; try { await _postServices.UpdateAsync(post, imageBase64); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Post> > PostPost(CreateAndUpdateHttpPost post) { var postModel = post.Post; var uri = post.Uri; await _postServices.InsertAsync(postModel, uri); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPost", new { id = post.Post.Id }, post)); }
public async Task UpdateAsync(Post updatedEntity, string base64) { var createModel = new CreateAndUpdateHttpPost { Post = updatedEntity, Uri = base64 }; var pathWithId = $"{_professorHttpOptions.CurrentValue.PostPath}/{updatedEntity.Id}"; var httpContent = new StringContent(JsonConvert.SerializeObject(createModel), Encoding.UTF8, "application/json"); var httpResponseMessage = await _httpClient.PutAsync(pathWithId, httpContent); if (!httpResponseMessage.IsSuccessStatusCode) { await _signInManager.SignOutAsync(); } }