コード例 #1
0
        /// <summary>
        /// Get the db-context instance
        /// </summary>
        public static LibraryContext GetContext()
        {
            if (_context == null)
                _context = new LibraryContext();

            return _context;
        }
コード例 #2
0
 public ActionResult Edit(int id)
 {
     using (LibraryContext db = new LibraryContext())
     {
         Record b = db.Records.Find(id);
         return View(b);
     }
 }
コード例 #3
0
ファイル: AdminController.cs プロジェクト: ylyubimov/Library
 // GET: /Admin/
 public ActionResult Index()
 {   // Пока тут вывод информации об админе
     using (var db = new LibraryContext())
     {
         var adminInfo = (from admin in db.LibraryAdmins
                          select admin).First();
         return View(adminInfo);
     }
 }
コード例 #4
0
        public ActionResult Add(Record record)
        {
            using (LibraryContext db = new LibraryContext())
            {
                db.Records.Add(record);
                db.SaveChanges();

                return Redirect("/Record/Index");
            }
        }
コード例 #5
0
        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");
            }
        }
コード例 #6
0
ファイル: AdminController.cs プロジェクト: ylyubimov/Library
        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);
            }
        }
コード例 #7
0
ファイル: UserService.cs プロジェクト: cloudmark/Library
 public UserService(LibraryContext libraryContext)
 {
     this._libraryContext = libraryContext;
 }
コード例 #8
0
 public MemberRepository(LibraryContext ctx)
 {
     _context = ctx;
 }
コード例 #9
0
 public BookCopyRepository(LibraryContext ctx)
 {
     _context = ctx;
 }
コード例 #10
0
 public RepositoryFactory()
 {
     _context = ContextSingelton.GetContext();
 }
コード例 #11
0
        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();
                }
            }
        }
コード例 #12
0
ファイル: Helper.cs プロジェクト: Smi1le/Library
        static public int GetNumberBookOnHands(Book book, LibraryContext context)
        {
            var b = context.IssuedBooks.Where(s => s.Id_book == book.Id);

            return(b.Count());
        }
コード例 #13
0
ファイル: BookService.cs プロジェクト: cloudmark/Library
 public BookService(LibraryContext libraryContext)
 {
     this._libraryContext = libraryContext;
 }
コード例 #14
0
ファイル: LoanServices.cs プロジェクト: cloudmark/Library
 public LoanService(LibraryContext libraryContext, IBookService bookService, IUserService userService)
 {
     this._libraryContext = libraryContext;
     this._bookService = bookService;
     this._userService = userService;
 }
コード例 #15
0
ファイル: AdminController.cs プロジェクト: ylyubimov/Library
 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);
     }
 }
コード例 #16
0
ファイル: AdminController.cs プロジェクト: ylyubimov/Library
 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);
     }
 }
コード例 #17
0
 public LoanRepository(LibraryContext ctx)
 {
     _context = ctx;
 }
コード例 #18
0
ファイル: AdminController.cs プロジェクト: ylyubimov/Library
        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", "Издатель с таким названием уже существует");
                }
            }
        }
コード例 #19
0
 public AuthorRepository(LibraryContext ctx)
 {
     _context = ctx;
 }