/// <summary> /// Get the db-context instance /// </summary> public static LibraryContext GetContext() { if (_context == null) _context = new LibraryContext(); return _context; }
public ActionResult Edit(int id) { using (LibraryContext db = new LibraryContext()) { Record b = db.Records.Find(id); return View(b); } }
// GET: /Admin/ public ActionResult Index() { // Пока тут вывод информации об админе using (var db = new LibraryContext()) { var adminInfo = (from admin in db.LibraryAdmins select admin).First(); return View(adminInfo); } }
public ActionResult Add(Record record) { using (LibraryContext db = new LibraryContext()) { db.Records.Add(record); db.SaveChanges(); return Redirect("/Record/Index"); } }
public ActionResult Edit(int id, Record record) { using (LibraryContext db = new LibraryContext()) { Record b = db.Records.Find(id); b.RecordName = record.RecordName; b.RecordDescription = record.RecordDescription; db.SaveChanges(); return Redirect("/Record/Index"); } }
public ActionResult Add(Record record) { AddErrorsProcessing(record); if (ModelState.IsValid) { using (LibraryContext db = new LibraryContext()) { db.Publishers.Add(record.Author); db.Records.Add(record); db.SaveChanges(); return Redirect("/Admin/Index"); } } else { return View(record); } }
public UserService(LibraryContext libraryContext) { this._libraryContext = libraryContext; }
public MemberRepository(LibraryContext ctx) { _context = ctx; }
public BookCopyRepository(LibraryContext ctx) { _context = ctx; }
public RepositoryFactory() { _context = ContextSingelton.GetContext(); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new LibraryContext( serviceProvider.GetRequiredService < DbContextOptions <LibraryContext> >())) { if (!context.Book.Any()) { context.Book.AddRange( new Book { Title = "Czysty kod. Podręcznik dobrego programisty", Author = "Robert C. Martin", PublishingHouse = "Helion", ReleaseDate = DateTime.Parse("2014-10-15"), }, new Book { Title = "Czysty kod w Pythonie", Author = "Kapil Sunil", PublishingHouse = "Helion", ReleaseDate = DateTime.Parse("2020-05-12"), }, new Book { Title = "Python. Leksykon kieszonkowy", Author = "Lutz Mark", PublishingHouse = "Helion", ReleaseDate = DateTime.Parse("2019-08-08"), }, new Book { Title = "Linux. Komendy i polecenia", Author = "Sosna Łukasz", PublishingHouse = "Helion", ReleaseDate = DateTime.Parse("2018-08-29"), }, new Book { Title = "Język Python dla nastolatków. Zabawa w programowanie", Author = "Wiszniewski Michał", PublishingHouse = "Helion", ReleaseDate = DateTime.Parse("2017-04-14"), }, new Book { Title = "Personal Cybersecurity", Author = "Marvin Waschke", PublishingHouse = "Apress", ReleaseDate = DateTime.Parse("2018-07-14"), }, new Book { Title = "Practical Cryptography in Python", Author = "Seth James Nielson, Christopher K. Monson", PublishingHouse = "Apress", ReleaseDate = DateTime.Parse("2018-05-27"), }, new Book { Title = "Applied Cryptography in .NET and Azure Key Vault", Author = "Stephen Haunts", PublishingHouse = "Apress", ReleaseDate = DateTime.Parse("2017-11-21"), }, new Book { Title = "Hello! Raspberry Pi", Author = "Ryan Heitz", PublishingHouse = "Manning", ReleaseDate = DateTime.Parse("2019-01-12"), }, new Book { Title = "Get Programming with Python in Motion", Author = "Ana Bell", PublishingHouse = "Manning", ReleaseDate = DateTime.Parse("2018-05-08"), }, new Book { Title = "Beginning Programming For Dummies", Author = "Wallace Wang", PublishingHouse = "John Wiley & Sons Inc", ReleaseDate = DateTime.Parse("2006-12-01"), }, new Book { Title = "Python For Dummies", Author = "Stef Maruch", PublishingHouse = "John Wiley & Sons Inc", ReleaseDate = DateTime.Parse("2006-06-08"), } ); context.SaveChanges(); } } }
static public int GetNumberBookOnHands(Book book, LibraryContext context) { var b = context.IssuedBooks.Where(s => s.Id_book == book.Id); return(b.Count()); }
public BookService(LibraryContext libraryContext) { this._libraryContext = libraryContext; }
public LoanService(LibraryContext libraryContext, IBookService bookService, IUserService userService) { this._libraryContext = libraryContext; this._bookService = bookService; this._userService = userService; }
public ActionResult Edit(int? id) { int realId; if (id == null) { return new HttpStatusCodeResult(400, "Expected books id"); } else { realId = (int)id; } using (LibraryContext db = new LibraryContext()) { bool idIsValid = (from r in db.Records select r.RecordId).Contains(realId); if (!idIsValid) { return new HttpStatusCodeResult(404, "No book with such id: " + realId); } Record currentBook = (from r in db.Records where r.RecordId == realId select r).First(); Publisher currentPublisher = (from p in db.Publishers where p.PublisherId == currentBook.PublisherId select p).First(); AdminEditModel viewModel = new AdminEditModel(currentBook, currentPublisher); return View(viewModel); } }
public ActionResult Edit(int id, AdminEditModel viewModel) { if (ModelState.IsValid) { using (LibraryContext db = new LibraryContext()) { var recordQuery = (from r in db.Records where r.RecordId == id select r).First(); var publisherQuery = (from p in db.Publishers where p.PublisherId == recordQuery.PublisherId select p).First(); ChangeEntities(recordQuery, publisherQuery, viewModel); db.SaveChanges(); return Redirect("/Admin/Index"); } } else { return View(viewModel); } }
public LoanRepository(LibraryContext ctx) { _context = ctx; }
private void AddErrorsProcessing(Record record) { using (LibraryContext db = new LibraryContext()) { if (db.Records.Where(rec => rec.RecordName == record.RecordName).Count() > 0) { ModelState.AddModelError("RecordName", "Книга с таким названием уже существует"); } // todo: проверка ниже нужна для будущего выпадающего списка: чтобы не создать нового publishera, если он существует if (db.Publishers.Where(rec => rec.PublisherName == record.Author.PublisherName).Count() > 0) { ModelState.AddModelError("Author.PublisherName", "Издатель с таким названием уже существует"); } } }
public AuthorRepository(LibraryContext ctx) { _context = ctx; }