public static void IsValid(LibraryAccount account) { Assert.IsNotNull(account); Assert.AreNotEqual(Guid.Empty, account.Id); Assert.IsValidKey(account.Number, 128); Assert.IsValidKey(account.Owner, 512); }
private async Task PostLibraryAccount() { if (!string.IsNullOrWhiteSpace(SurNameField.Text) && !string.IsNullOrWhiteSpace(FirstNameField.Text) && !string.IsNullOrWhiteSpace(SerialField.Text) && !string.IsNullOrWhiteSpace(NumberField.Text)) { var accountNumber = await GenerateAccountNumber(); LibraryAccount libraryAccount = new LibraryAccount { SurName = SurNameField.Text, FirstName = FirstNameField.Text, PassportSerial = Convert.ToInt32(SerialField.Text), PassportNumber = Convert.ToInt32(NumberField.Text), AccountNumber = accountNumber }; try { await _accountsProxy.AddLibraryAccount(libraryAccount); } catch (HttpException ex) { MessageBox.Show($"Ошибка:{ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ex; } } else { MessageBox.Show("Укажите данные о человеке в верном формате", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
LibraryAccount ILibraryAccountService.Create(string number, string owner) { var account = new LibraryAccount(number, owner); _repository.Add(account); return(account); }
public async Task <ActionResult <LibraryAccount> > PostLibraryAccount(LibraryAccount libraryAccount) { _context.LibraryAccounts.Add(libraryAccount); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLibraryAccount", new { id = libraryAccount.AccountID }, libraryAccount)); }
public async Task <IActionResult> PutLibraryAccount(int id, LibraryAccount libraryAccount) { if (id != libraryAccount.AccountID) { return(BadRequest()); } _context.Entry(libraryAccount).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LibraryAccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Interaction(LibraryAccount account, IEnumerable<Book> books) { var borrower = account.ActAs<IBorrower>(); foreach (var book in books) { borrower.BorrowBook(book); } }
/// <summary> /// 借书 /// </summary> /// <returns></returns> public bool BorrowBooks(LibraryAccount libraryAccount, List<Book> books) { if (libraryAccount == null || books == null) return false; new BorrowBooksContext().Interaction(libraryAccount, books); return true; }
public LibraryAccount Create(string number, string owner) { using (var context = _contextManager.GetContext()) { var account = new LibraryAccount(number, owner); context.Add(account); context.SaveChanges(); return account; } }
public void LendBook(Book book, LibraryAccount libraryAccount) { var bookStoreInfo = bookStoreInfoRepository.GetBookStoreInfo(book.Id); if (bookStoreInfo.Count == 0) { throw new Exception(string.Format("The count of book '{0}' in library is zero, so you cannot borrow it.", book.BookName)); } bookStoreInfo.DecreaseCount(); //数量减1 //生成借书信息并保存到Repository中 borrowInfoRepository.Add(new BorrowInfo(book, libraryAccount, DateTime.Now)); }
public void ReceiveReturnedBook(Book book, LibraryAccount libraryAccount) { //设置借书信息的还书时间 var borrowedInfo = borrowInfoRepository.FindNotReturnedBorrowInfo(libraryAccount.Id, book.Id); borrowedInfo.ReturnTime = DateTime.Now; //这里,真正的系统还会计算归还时间是否超期,计算罚款之类的逻辑,因为我这个是一个演示的例子,所以不做这个处理了 //这里只更新书本的数量信息,因为还书时并不是马上把书本放回书架的,所以此时书本的书架位置信息还是保留为空 //等到我们将这本书放到书架的某个位置时,才会更新其位置信息 var bookStoreInfo = bookStoreInfoRepository.GetBookStoreInfo(book.Id); bookStoreInfo.IncreaseCount(); //数量加1 }
public async Task <HttpStatusCode> PostLibraryAccount([FromBody] LibraryAccount libraryAccount) { try { _context.LibraryAccounts.Add(libraryAccount); await _context.SaveChangesAsync(); return(HttpStatusCode.Created); } catch (Exception) { return(HttpStatusCode.NoContent); } }
public async Task <LibraryAccount> AddLibraryAccount(LibraryAccount libraryAccount) { var jsonString = JsonConvert.SerializeObject(libraryAccount); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("/api/LibraryAccounts", content); var code = response.StatusCode; var result = responseReader.ReadObjectAsync <LibraryAccount>(response); if (code == (HttpStatusCode)200) { return(await result); } return(null); }
public void BorrowBooks() { IInstanceLocator ioc = IocFactory.CreateIoc(); var book1 = new Book { BookName = "C#高级编程", Author = "Jhon Smith", ISBN = "56-YAQ-23452", Publisher = "清华大学出版社", Description = "A very good book." }; var book2 = new Book { BookName = "JQuery In Action", Author = "Jhon Smith", ISBN = "09-BEH-23452", Publisher = "人民邮电出版社", Description = "A very good book." }; IBookRepository bookRepository = ioc.GetInstance<IBookRepository>(); bookRepository.Add(book1); bookRepository.Add(book2); //创建一个图书馆用户帐号,用户凭帐号借书 var libraryAccount = new LibraryAccount("12345678876543") { OwnerName = "赖小天", IsLocked = false }; ILibraryAccountRepository libraryAccountRepository = ioc.GetInstance<ILibraryAccountRepository>(); libraryAccountRepository.Add(libraryAccount); //创建并启动借书场景 new BorrowBooksContext().Interaction(libraryAccount, new List<Book> { book1, book2 }); }
private static void BorrowReturnBookExample() { PrintDescriptionBeforeExample(); //创建2本书 var book1 = new Book { BookName = "C#高级编程", Author = "Jhon Smith", ISBN = "56-YAQ-23452", Publisher = "清华大学出版社", Description = "A very good book." }; var book2 = new Book { BookName = "JQuery In Action", Author = "Jhon Smith", ISBN = "09-BEH-23452", Publisher = "人民邮电出版社", Description = "A very good book." }; bookRepository.Add(book1); bookRepository.Add(book2); //创建一个图书馆用户帐号,用户凭帐号借书 var libraryAccount = new LibraryAccount(GenerateAccountNumber(10)) { OwnerName = "赖小天", IsLocked = false }; libraryAccountRepository.Add(libraryAccount); PrintAccountInfo(libraryAccount); //创建并启动图书入库场景 PrintDescriptionBeforeStoreBookContext(book1, book2); new StoreBookContext(library, book1).Interaction(2, "4F-S-0001"); new StoreBookContext(library, book2).Interaction(3, "4F-N-0002"); PrintBookCount(book1, book2); //创建并启动借书场景 PrintDescriptionBeforeContext1(libraryAccount, book1, book2); new BorrowBooksContext().Interaction(libraryAccount, new List<Book> { book1, book2 }); PrintBorrowedInfo(libraryAccount); PrintBookCount(book1, book2); //创建并启动还书场景 PrintDescriptionBeforeContext2(libraryAccount, book1); new ReturnBooksContext().Interaction(libraryAccount, new List<Book> { book1 }); PrintBorrowedInfo(libraryAccount); PrintBookCount(book1, book2); //创建并启动图书出库 PrintDescriptionBeforeOutBookContext(book1, book2); new OutBookContext(library, book1).Interaction(1); new OutBookContext(library, book2).Interaction(1); PrintBookCount(book1, book2); }
private static void PrintAccountInfo(LibraryAccount libraryAccount) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(string.Format("创建了一个图书馆用户帐号:{0},帐号拥有者:{1}", libraryAccount.Number, libraryAccount.OwnerName)); }
private static void PrintDescriptionBeforeContext2(LibraryAccount libraryAccount, Book book1) { Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(string.Format("还书场景:帐号{0}还了一本书:", libraryAccount.Number)); Console.ForegroundColor = ConsoleColor.White; Console.Write(book1.BookName); }
public void ReceiveReturnedBook(Book book, LibraryAccount libraryAccount) { }
public void LendBook(Book book, LibraryAccount libraryAccount) { borrowInfoRepository.Add(new BorrowInfo(book, libraryAccount, DateTime.Now)); }
LibraryAccount ILibraryAccountService.Create(string number, string owner) { var account = new LibraryAccount(number, owner); _repository.Add(account); return account; }
public bool BorrowBooks(LibraryAccount libraryAccount, List<Book> books) { Application.MainBoundedContext.ILibraryService libraryService = new Application.MainBoundedContext.LibraryService(); return libraryService.BorrowBooks(libraryAccount, books); }
private static void PrintBorrowedInfo(LibraryAccount libraryAccount) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(""); Console.WriteLine(string.Format("帐号{0}当前借的书本:", libraryAccount.Number)); Console.ForegroundColor = ConsoleColor.White; foreach (var borrowedInfo in borrowInfoRepository.FindNotReturnedBorrowInfos(libraryAccount.Id)) { Console.WriteLine("书名:{0}", borrowedInfo.Book.BookName); } }