public ActionResult Create(Title title) { title.CreateDay = DateTime.Now; _context.Titles.Add(title); _context.SaveChanges(); return(Ok(title)); }
public void ResetDebtors() { var clients = context.Clients.Where(x => x.IsDebtor == true).ToList(); clients.ForEach(x => x.IsDebtor = false); context.Clients.UpdateRange(clients); context.SaveChanges(); }
public void CheckDebtor() { var bookOnHands = context.BooksOnHands.ToList(); var books = bookOnHands.Where(book => book.ReturnDate < DateTime.Now).ToList(); if (books.Count == 0) { return; } books.ForEach(x => x.User.Debtor = true); foreach (var book in books) { context.Entry(book).State = EntityState.Modified; } context.SaveChanges(); }
public LibrarianController(LibaryContext context) { _context = context; if (_context.Librarians.ToList().Count == 0) { Librarian librarian = new Librarian { Account = "libarian1", PassWord = "******", Name = "vanteo", Gender = true, Email = "*****@*****.**", Phone = "0969696969", CreateDay = DateTime.Now, CreateBy = 1, }; _context.Librarians.Add(librarian); _context.SaveChanges(); } }
public MemberController(LibaryContext context) { _context = context; if (_context.Librarians.ToList().Count == 0) { Member mem = new Member { Account = "mem1", PassWord = "******", Name = "vanteo", Gender = true, Email = "*****@*****.**", Phone = "0969696969", CreateDay = DateTime.Now, CreateBy = 1, }; _context.Members.Add(mem); _context.SaveChanges(); } }
private void FillTables() { var firstClient = new Client { FullName = "Наруто Удзумаки", IsDebtor = false }; var secondClient = new Client { FullName = "Саске Учиха", IsDebtor = true }; var thirdClient = new Client { FullName = "Олег Сергеевич", IsDebtor = true }; var firstAuthor = new Author { FullName = "Джирайя" }; var secondAuthor = new Author { FullName = "Джоан Роулинг" }; var thirdAuthor = new Author { FullName = "Масаши Кишимото" }; var firstBook = new Book { TitleName = "Наруто: Ураганные Хроники" }; var secondBook = new Book { TitleName = "Гарри Поттер" }; var thirdBook = new Book { TitleName = "Наруто Поттер, тактика" }; var fourthBook = new Book { TitleName = "Приди, приди, тактика" }; var firstBooksAuthors = new BooksAuthors { Book = firstBook, Author = thirdAuthor }; var secondBooksAuthors = new BooksAuthors { Book = secondBook, Author = secondAuthor }; var thirdBooksAuthors = new BooksAuthors { Book = thirdBook, Author = firstAuthor }; var fourthBooksAuthors = new BooksAuthors { Book = fourthBook, Author = firstAuthor }; var firstEntry = new LibraryEntry { Book = firstBook, Client = firstClient, ReturnDate = DateTime.Now }; var secondEntry = new LibraryEntry { Book = secondBook, Client = firstClient, ReturnDate = DateTime.Now }; var thirdEntry = new LibraryEntry { Book = thirdBook, Client = secondClient, ReturnDate = DateTime.Now }; context.BooksAuthors.AddRange( new BooksAuthors { Book = thirdBook, Author = secondAuthor }, thirdBooksAuthors, new BooksAuthors { Book = thirdBook, Author = thirdAuthor }); context.Clients.AddRange(firstClient, secondClient, thirdClient); context.Authors.AddRange(firstAuthor, secondAuthor, thirdAuthor); context.Books.AddRange(firstBook, secondBook, thirdBook, fourthBook); context.BooksAuthors.AddRange(firstBooksAuthors, secondBooksAuthors, fourthBooksAuthors); context.LibraryEntries.AddRange(firstEntry, secondEntry, thirdEntry); context.SaveChanges(); }