示例#1
0
 private static void AddNewRecord(Books books)
 {
     using (var repo = new BooksRepo())
     {
         repo.Add(books);
     }
 }
        public async Task<ActionResult> Create(IFormCollection form)
        {
            try
            {
                await _booksRepo.Add(new Book()
                {
                    Id = new Guid(),
                    Title = form["Title"],
                    Author = form["Author"],
                    ReleaseDate = Convert.ToDateTime(form["ReleaseDate"]),
                    Description = form["Description"]
                });

                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }
示例#3
0
        public static async Task InitDB(ApplicationDbContext context)
        {
            BooksRepo   booksRepo = new BooksRepo(context);
            List <Book> books     = await booksRepo.GetAll();

            foreach (var newBook in GetBooks())
            {
                foreach (var book in books)
                {
                    if ((newBook.Title == book.Title &&
                         newBook.Author == book.Author &&
                         newBook.ReleaseDate == book.ReleaseDate &&
                         newBook.Description == book.Description))
                    {
                        goto OuterLoop;
                    }
                }

                await booksRepo.Add(newBook);

OuterLoop:
                continue;
            }
        }
示例#4
0
 public void Add(BookViewModel bookViewModel)
 {
     repo.Add(Mapper.Map <Book>(bookViewModel));
 }