Beispiel #1
0
        /// <summary>
        /// ApplyPatching()
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        public async Task ApplyPatching(PatchBookViewModel vm)
        {
            BookLoanComparer bookLoanComparer = new BookLoanComparer();

            if (vm.books.Count > 0)
            {
                foreach (BookViewModel book in vm.books)
                {
                    BookLoan.Models.BookViewModel bookoriginal = await _db.Books.
                                                                 Where(m => m.ID == book.ID).SingleOrDefaultAsync();

                    if (bookoriginal != null)
                    {
                        // If different record then update
                        if (!bookLoanComparer.Equals(bookoriginal, book))
                        {
                            await this.UpdateBook(book.ID, book);
                        }
                    }
                    else
                    {
                        // If a new record then insert
                        if (book.ID == 0)
                        {
                            await this.SaveBook(book);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        // GET: LoanViewModels/GetBookLoanStatus/5

        /// <summary>
        /// GetBook()
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BookViewModel> GetBook(int id)
        {
            BookLoan.Models.BookViewModel book = await _db.Books.
                                                 Where(m => m.ID == id).SingleOrDefaultAsync();

            if (book != null)
            {
                return(book);
            }
            return(null);
        }
 //[Route("Delete/{id}")]
 public ActionResult Delete(int id, BookLoan.Models.BookViewModel collection)
 // IFormCollection collection)
 {
     try
     {
         // TODO: Add delete logic here
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(BadRequest());
     }
 }