Exemple #1
0
        public async Task <bool> UpdateBookAsync(string id, UpdateBookResource book)
        {
            var result = await _libraryClient
                         .ExternalPatchApiResultAsync(string.Format(_serviceUrl.Value.UpdateBook, id),
                                                      JsonConvert.SerializeObject(book),
                                                      _headers);

            return(result.StatusCode == StatusCodes.Status204NoContent);
        }
Exemple #2
0
        public async Task <bool> UpdateBookAsync(string id, UpdateBookResource resource)
        {
            Expression <Func <Models.Book, bool> > predicate = p => p.Id == id;
            var existingBook = await _dbRepo.GetByIdAsync(predicate);

            if (existingBook == null)
            {
                throw new Exception("Specified book not found");
            }

            existingBook.Author = resource.Author;
            existingBook.Name   = resource.Name;

            return(await _dbRepo.UpdateAsync(id, existingBook));
        }
Exemple #3
0
        public ActionResult Edit(string id, IFormCollection collection)
        {
            try
            {
                var updateResource = new UpdateBookResource
                {
                    Author = collection["Author"].ToString(),
                    Name   = collection["Name"].ToString()
                };
                var isBookUpdated = _bookService.UpdateBookAsync(id, updateResource);

                if (isBookUpdated.Result)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }