Ejemplo n.º 1
0
 private void InitBook(BookViewModel book, Action<Exception> callback)
 {
     _bookService.GetBookRegNo((regno, ex) =>
     {
         if (ex != null)
         {
             callback(ex);
             return;
         }
         var configService = ServiceLocator.Current.GetInstance<IConfigService>();
         configService.GetValue("default_comment", (default_comment, ex2) =>
         {
             if (ex != null)
             {
                 callback(ex);
                 return;
             }
             book.RegNo = (int)regno;
             book.Comment = (string)(JValue)default_comment;
             callback(null);
         });
     });
 }
 private void Search()
 {
     if (RegNo != null)
     {
         _checkoutService.GetBook((int)RegNo, (book, ex) =>
         {
             if (ex != null)
             {
                 Book = null;
                 Status = CoStatus.NOSELECT;
                 MessageBox.Show(App.Current.MainWindow, ex.Message);
                 return;
             }
             Book = new BookViewModel(book);
         });
         _checkoutService.GetCheckouts(null, RegNo, false, null, null, 0, -1, (checkouts, ex) =>
         {
             if (ex != null)
             {
                 MessageBox.Show(App.Current.MainWindow, ex.Message);
                 return;
             }
             var checkout = checkouts.Checkouts.FirstOrDefault();
             if (checkout != null)
             {
                 if (checkout.account == Account)
                 {
                     // 返却できます
                     Status = CoStatus.CIOK;
                 }
                 else
                 {
                     // 貸出中
                     Status = CoStatus.OTHERCO;
                 }
             }
             else
             {
                 if (Book != null)
                 {
                     // 貸出できます
                     Status = CoStatus.COOK;
                 }
                 else
                 {
                     Status = CoStatus.NOSELECT;
                 }
             }
         });
     }
     else
     {
         Book = null;
         Status = CoStatus.NOSELECT;
     }
     if (!string.IsNullOrEmpty(Account))
     {
         _checkoutService.GetUser(Account, (user, ex) =>
         {
             if (ex != null)
             {
                 User = null;
                 Checkouts = null;
                 TotalCount = 0;
                 SelectedCheckout = null;
                 Status = CoStatus.NOSELECT;
                 MessageBox.Show(App.Current.MainWindow, ex.Message);
                 return;
             }
             User = new UserViewModel(user);
         });
         _checkoutService.GetCheckouts(Account, null, false, null, null, 0, -1, (checkouts, ex) =>
         {
             if (ex != null)
             {
                 MessageBox.Show(App.Current.MainWindow, ex.Message);
                 return;
             }
             Checkouts = new ObservableCollection<CheckoutViewModel>(checkouts.Checkouts.Select(t => new CheckoutViewModel(t)));
             TotalCount = checkouts.TotalCount;
             if (Checkouts != null)
                 SelectedCheckout = Checkouts.Where(t => t.RegNo == RegNo).FirstOrDefault();
         });
     }
     else
     {
         User = null;
         Checkouts = null;
         TotalCount = 0;
         SelectedCheckout = null;
         Status = CoStatus.NOSELECT;
     }
 }