示例#1
0
        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));
        }
示例#2
0
        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());
            }
        }
示例#3
0
        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));
        }
示例#4
0
        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());
        }
示例#5
0
 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));
 }