public AuthorController(AuthorContext context) { _context = context; if (_context.Authors.Count() == 0) { _context.Authors.Add(new Author { firstName = "FirstName", lastName = "LastName" }); _context.SaveChanges(); } }
public AuthorsController(AuthorContext context) { this._context = context; if (this._context.AuthorsList.Count() == 0) { _context.AuthorsList.Add(new Author { Name = "First Author" }); _context.SaveChanges(); } }
public async static Task Main(string[] args) { //SetupDB(); using AuthorContext ac = new AuthorContext(); List <Author> authors = ac.Authors. Where(a => a.Id == 1). Include(a => a.Books). ThenInclude(b => b.Genres). Include(a => a.Address) .ToList(); int stophere = 0; }
public AuthorController(AuthorContext context) { _context = context; if (_context.authors.Count() == 0) { _context.authors.Add(new Author { firstName = "Profesor", lastName = "Uno", bornDate = DateTime.Now.Date }); _context.SaveChanges(); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { Author user = null; using (AuthorContext db = new AuthorContext()) { user = db.Authors.FirstOrDefault(u => u.Email == model.Name); } if (user == null) { // создаем нового пользователя using (AuthorContext db = new AuthorContext()) { if (model.Email != null && model.Name != null && model.Password != null) { db.Authors.Add(new Author { Email = model.Email, Name = model.Name, Password = model.Password }); db.SaveChanges(); user = db.Authors.Where(u => u.Email == model.Email && u.Password == model.Password) .FirstOrDefault(); } else { ModelState.AddModelError("", "Please, enter registration data"); } } // если пользователь удачно добавлен в бд if (user != null) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("AddArticle", "Home")); } } else { ModelState.AddModelError("", "This login already exists in another user"); } } return(View(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { // поиск пользователя в бд Author user = null; using (AuthorContext db = new AuthorContext()) { user = db.Authors.FirstOrDefault(u => u.Email == model.Email && u.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("AddArticle", "Home")); } else { ModelState.AddModelError("", "Your password or login is incorrect"); } } return(View(model)); }
static void Main(string[] args) { var mongoClient = new MongoClient(); var bookCtx = new BookContext(mongoClient); /* * var query = new Queries(bookCtx); * * query.DisplayTotal(); * * query.DisplayByAuthor("Ann Beattie"); * query.DisplayByPublicationYear(2005); * * * var genAuth = new GenerateAuthors(new AuthorContext(mongoClient), bookCtx); * genAuth.StartGeneration(); * * var bookCtxNew = new BookContextNew(mongoClient); * */ var authCtx = new AuthorContext(mongoClient); /* * var genNewBooks = new GenerateNewBooks(bookCtxNew, authCtx, bookCtx); * genNewBooks.StartGeneration(); */ /* * Not a good option, too slow * Better let the Mongo driver to work instead * var genNewBooks = new PGenerateNewBooks(); * genNewBooks.StartGenerationParallel(); * */ Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
private async void Read() { var mongoClient = new MongoClient(); var bookCtx = new BookContext(mongoClient); var authCtx = new AuthorContext(mongoClient); var books = bookCtx.QBooks.AsParallel(); var authors = authCtx.QAuthors.AsParallel(); books.ForAll(b => { var author = authors.FirstOrDefault(a => a.Name == b.Author); if (author != null) { b.Author = null; b.AuthorId = author.Id; NewBooks.Enqueue(b); } }); readFinished = true; }
public BookTitlesController(AuthorContext context, IBookTitleRepository bookRepo) { _context = context; _bookRepo = bookRepo; }
public GenresController(AuthorContext context) { _context = context; }
public BookTitleRepository(AuthorContext context) { _context = context; }
public Handler(AuthorContext context) { authorContext = context; }
public GenerateAuthors(AuthorContext autCtx, BookContext bookCtx) { this.autCtx = autCtx; this.bookCtx = bookCtx; }
public ReviewsController(AuthorContext context, IReviewRepository reviewRepo, IBookTitleRepository bookTitleRepo) { _context = context; _reviewRepo = reviewRepo; _bookTitleRepo = bookTitleRepo; }
private static void SetupDB() { Genre fantasy = new Genre { Name = "Fantasy" }; Genre urban = new Genre { Name = "Urban" }; Genre superheroes = new Genre { Name = "Superheroes" }; Genre scifi = new Genre { Name = "Scifi" }; Genre magic = new Genre { Name = "Magic" }; Book b1 = new() { Title = "Rythm of War", PageCount = 1232, PublicationYear = 2020, ISBN = "0765326388", Genres = new List <Genre> { fantasy, magic } }; Book b2 = new() { Title = "The Alloy of Law", PageCount = 332, PublicationYear = 2011, ISBN = "0765330423", Genres = new List <Genre> { urban, fantasy, magic } }; Book b3 = new() { Title = "Steelheart", PageCount = 386, PublicationYear = 2013, ISBN = "0385743564", Genres = new List <Genre> { superheroes, urban, scifi } }; Book b4 = new() { Title = "Judgment of Mars", PageCount = 270, PublicationYear = 2017, ISBN = "34538192", Genres = new List <Genre> { scifi, fantasy, magic } }; Book b5 = new() { Title = "Blood of the Innocent", PageCount = 322, PublicationYear = 2017, ISBN = "35823660", Genres = new List <Genre> { urban, fantasy } }; Author brandon = new Author { FirstName = "Brandon", LastName = "Sanderson", Address = new() { Street = "Nowhere", HouseNumber = 3, PostCode = 837 }, Books = new List <Book> { b1, b2, b3 } }; Author glynn = new Author { FirstName = "Glynn", LastName = "Stewart", Address = new() { Street = "Anywhere", HouseNumber = 7, PostCode = 824 }, Books = new List <Book> { b4, b5 } }; using AuthorContext ac = new AuthorContext(); ac.Add(brandon); ac.Add(glynn); ac.SaveChanges(); } } }
public AuthorsController(AuthorContext context, IAuthorRepository authorRepo) { _context = context; _authorRepo = authorRepo; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AuthorContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public AuthorRepository(AuthorContext context) { _context = context; }
public Handler(AuthorContext authorContext) { this._authorContext = authorContext; }
public Manage(AuthorContext contexto, IMapper mapper) { _contexto = contexto; _mapper = mapper; }
public AuthorRepository(AuthorContext authorContext) { this.authorContext = authorContext; }
public Handler(AuthorContext contexto, IMapper mapper) { this._context = contexto; this._mapper = mapper; }
public Handler(AuthorContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public ReviewRepository(AuthorContext context) { _context = context; }
public AuthorController(AuthorContext context) { _context = context; }
public Manage(AuthorContext contexto) { _contexto = contexto; }
public GenerateNewBooks(BookContextNew newBookCtx, AuthorContext autCtx, BookContext bookCtx) { this.newBookCtx = newBookCtx; this.autCtx = autCtx; this.bookCtx = bookCtx; }
public AuthorEntityBinder(AuthorContext context) { _context = context; }
public AuthorRepository(IOptions <DatabaseSettings> options) { _context = new AuthorContext(options) ?? throw new ArgumentNullException(nameof(options)); }
public BookTitleGenresController(AuthorContext context) { _context = context; }