예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,AuthorName,Date")] Authors authors)
        {
            int counter = 0;

            foreach (var g in _context.Authors)
            {
                if (g.AuthorName == authors.AuthorName)
                {
                    counter++; break;
                }
            }

            if (counter != 0)
            {
                ModelState.AddModelError("AuthorName", "Таке ім'я вже існує");
                return(View(authors));
            }
            else
            {
                if (authors.Date > DateTime.Now)
                {
                    ModelState.AddModelError("Date", "Неправильна дата");
                    return(View(authors));
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        _context.Add(authors);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(authors));
                }
            }
        }
예제 #2
0
        public void AddOrEditBookBorrow(string studentId, string bookId, DateTime borrowDate, DateTime?returnDate, int?bookBorrowId)
        {
            var student = _context.Students.Find(int.Parse(studentId.OnlyNumbers()));
            var book    = _context.Books.Find(int.Parse(bookId.OnlyNumbers()));

            if (bookBorrowId == null)
            {
                _context.Add(new BookBorrow()
                {
                    Student    = student,
                    Book       = book,
                    BorrowDate = borrowDate
                });
                _context.SaveChanges();

                return;
            }

            _context.BookBorrows.Find(bookBorrowId).Student    = student;
            _context.BookBorrows.Find(bookBorrowId).Book       = book;
            _context.BookBorrows.Find(bookBorrowId).BorrowDate = borrowDate;
            _context.BookBorrows.Find(bookBorrowId).ReturnDate = returnDate;
            _context.SaveChanges();
        }
        public IActionResult Add(BookModel bm)
        {
            Book b = new Book();

            if (bm.Title != null || bm.Year != 0 || bm.ImagePath != null || bm.Tags != null || bm.Author != null || bm.PhoneNo != null)
            {
                b.Title = bm.Title;
                b.Year  = bm.Year;
                try
                {
                    b.Image = System.IO.File.ReadAllBytes(bm.ImagePath);
                }
                catch
                {
                    return(RedirectToAction("Index", "AddBook", new { m = "Image doesn't exist" }));
                }
                b.Tags    = bm.Tags;
                b.Author  = bm.Author;
                b.PhoneNo = bm.PhoneNo;
                if ((_context.Books.Where(x => (x.Title == b.Title && x.Year == b.Year && x.Author == b.Author)).Count()) > 0)
                {
                    return(RedirectToAction("Index", "AddBook", new { m = "Book already exists!" }));
                }
                try
                {
                    _context.Add(b);
                    _context.SaveChanges();
                    return(RedirectToAction("Index", "AddBook", new { m = "successfully added" }));
                }
                catch
                {
                    return(RedirectToAction("Index", "AddBook", new { m = "Error" }));
                }
            }
            return(RedirectToAction("Index", "AddBook", new { m = "Empty Fileds" }));
        }
예제 #4
0
 public Book Add(Book book)
 {
     book.IsAvailable = true;
     return(context.Add(book).Entity);
 }
        private async Task AddBookToInventory()
        {
            int?bookNum = await validateBookNumber();

            if (!bookNum.HasValue)
            {
                txtBookNumber.SelectAll();
                txtBookNumber.Focus();
                return;
            }
            if (!validateAgeRestrictions())
            {
                return;
            }
            if (!validateGradeRestrictions())
            {
                return;
            }

            CatalogEntry entry;

            if (tbiLocal.IsSelected)
            {
                if (lvwLocal.SelectedValue == null || !(lvwLocal.SelectedValue is CatalogEntry catalogEntry))
                {
                    return;
                }
                entry = catalogEntry;
            }
            else if (tbiGoogle.IsSelected)
            {
                if (googleSearch.SelectedVolume == null)
                {
                    return;
                }
                entry = CreateEntryFromGoogle(googleSearch.SelectedVolume);
            }
            else if (tbiManual.IsSelected)
            {
                if (!manualEditor.Validate())
                {
                    manualEditor.Focus();
                    return;
                }
                entry = manualEditor.SelCatalogEntry;
            }
            else
            {
                return;
            }
            if (!tbiLocal.IsSelected)
            {
                _db.Add(entry);
            }
            entry.MaxAge        = ageRestrict.MaxAge;
            entry.MinAge        = ageRestrict.MinAge;
            entry.MinGrade      = gradeRestrict.MinGrade;
            entry.MaxGrade      = gradeRestrict.MaxGrade;
            entry.ShelfLocation = txtShelf.Text.Trim();
            entry.AddOwnedBook(bookNum.Value);
            await _db.SaveChangesAsync();

            await updateMaxBookNumber();

            txtBookNumber.Clear();
            ClearSearch();
        }
예제 #6
0
 public void Add(LibraryBranch newBranch)
 {
     _context.Add(newBranch);
     _context.SaveChanges();
 }
 public void Add(LibraryAsset newAsset)
 {
     context.Add(newAsset);
     context.SaveChanges();
 }
예제 #8
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }
 public void Add(Book newBook)
 {
     _context.Add(newBook);
     _context.SaveChanges();
 }
예제 #10
0
 public void Add(LibraryAsset Asset)
 {
     _context.Add(Asset); // EF сама знайде до якої таблиці добавити сутність
     _context.SaveChanges();
 }
예제 #11
0
 public async Task AddAsync(LibraryBranch newBranch)
 {
     _context.Add(newBranch);
     await _context.SaveChangesAsync();
 }
예제 #12
0
 public void add(LibraryAsset newAsset)
 {
     //Add to newAsset and save the changes made
     _context.Add(newAsset);
     _context.SaveChanges();
 }
예제 #13
0
 public History Add(History history)
 {
     return(context.Add(history).Entity);
 }
 public void Add(Member newMember)
 {
     _context.Add(newMember);
     _context.SaveChanges();
 }
예제 #15
0
 public void Add(ILibraryAsset newAsset)
 {
     _context.Add(newAsset);
     _context.SaveChanges();
 }
 public void Add(Video newVideo)
 {
     _context.Add(newVideo);
     _context.SaveChanges();
 }
 public void Add(CheckOut newCheckout)
 {
     _Context.Add(newCheckout);
     _Context.SaveChanges();
 }
예제 #18
0
 public IActionResult Post(EmpTB empTB)
 {
     libraryContext.Add(empTB);
     libraryContext.SaveChanges();
     return(Ok(empTB));
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var context = new LibraryContext();

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
            //context.Database.Migrate();

            context.Add(new Author()
            {
                Id    = Guid.NewGuid(),
                Name  = "Santiago Posteguillo",
                Books = new List <Book>()
                {
                    new Book()
                    {
                        Id   = Guid.NewGuid(),
                        Name = "Africanus"
                    },
                    new Book()
                    {
                        Id   = Guid.NewGuid(),
                        Name = "Las legiones malditas"
                    }
                }
            });
            context.Add(new Author()
            {
                Id = Guid.NewGuid(), Name = "Simon Scarrow"
            });
            context.Add(new Author()
            {
                Id = Guid.NewGuid(), Name = "Steven Pressfiel"
            });
            context.Add(new Author()
            {
                Id = Guid.NewGuid(), Name = "Orson Scott"
            });
            context.Add(new Author()
            {
                Id = Guid.NewGuid(), Name = "John Scalzi"
            });

            context.SaveChanges();

            Console.WriteLine();

            var author = context.Set <Author>()
                         .Include(x => x.Books)
                         .FirstOrDefault();

            Console.WriteLine($"Author - First: {author.Name}; Books: {string.Join(",", author.Books.Select(b => b.Name))}");

            Console.WriteLine();
            Console.WriteLine($"Author - List");
            var authors = context.Set <Author>().ToList();

            authors.ForEach(a => Console.WriteLine(a.Name));

            var books = context.Set <Book>().ToList();



            Console.WriteLine();
            Console.WriteLine("Press enter to exit");
            var h = Console.ReadLine();

            context.Dispose();
        }
 public void Add(Checkout checkout)
 {
     _context.Add(checkout);
     _context.SaveChanges();
 }
 public void Add(Checkout newCheckout)
 {
     context.Add(newCheckout);
     context.SaveChanges();
 }
 public void Add(Status newStatus)
 {
     _context.Add(newStatus);
     _context.SaveChanges();
 }
예제 #23
0
 public void Add(LibraryAsset asset)
 {
     _context.Add(asset);
     _context.SaveChanges();
 }
예제 #24
0
파일: BooksR.cs 프로젝트: Rymzhan/Library
 public void Add(Books books)
 {
     _context.Add(books);
 }
 public void Add(LibraryAsset newAsset)
 {
     _context.Add(newAsset);
     _context.SaveChanges();     //commit to db
 }
예제 #26
0
 public void Add(LibraryAsset NewAsset)
 {
     _conntext.Add(NewAsset);
     _conntext.SaveChanges();
 }
예제 #27
0
 public void Add(Patron newPatron)
 {
     _context.Add(newPatron);
     _context.SaveChanges();
 }
 public async Task AddAsync(Checkout newCheckout)
 {
     _context.Add(newCheckout);
     await _context.SaveChangesAsync();
 }
 public void Add(Checkouts newCheckout)
 {
     _context.Add(newCheckout);
     _context.SaveChanges();
 }
예제 #30
0
 public Client Add(Client client)
 {
     return(context.Add(client).Entity);
 }