public async Task <IActionResult> AddShelfAsync(UpsertShelfViewModel shelfViewModel) { var currUser = User.FindFirst(ClaimTypes.NameIdentifier).Value; var id = await _shelfService.AddShelfAsync(shelfViewModel, currUser); return(CreatedAtAction(nameof(GetShelf), new { userId = currUser, shelfId = id }, null)); }
public async Task AddShelfAsync(UpsertShelfViewModel model) { var cnt = new StringContent(JsonSerializer.Serialize(model), Encoding.UTF8, _mediaType); var uri = ApiUri.Shelves.AddShelf(_remoteServiceBaseUrl); var resp = await _apiClient.PostAsync(uri, cnt); if (!resp.IsSuccessStatusCode) { throw new ApiException(await resp.Content.ReadAsStringAsync()); } }
public async Task <ActionResult> CreatePostAction(UpsertShelfViewModel model) { if (ModelState.IsValid) { await _shelfService.AddShelfAsync(model); TempData["message"] = $"Shelf \"{model.Name}\" was added."; return(RedirectToAction(nameof(Create))); } return(View(model)); }
public async Task <IActionResult> UpdateShelf(string shelfId, [FromBody] UpsertShelfViewModel shelfViewModel) { var result = await AuthorizeOperation(shelfId); if (result != null) { return(result); } await _shelfService.UpdateShelfAsync(shelfViewModel, shelfId); return(NoContent()); }
public async Task <ActionResult> EditPostAction(string shelfId, UpsertShelfViewModel model) { if (ModelState.IsValid) { if (await _shelfService.UpdateShelfAsync(shelfId, model)) { TempData["message"] = $"Shelf {model.Name} was successfully updated."; return(RedirectToAction(nameof(Index), new { userId = User.FindFirst(ClaimTypes.NameIdentifier).Value })); } else { return(NotFound()); } } return(View(model)); }