コード例 #1
0
        public AuthorController(AuthorContext context)
        {
            _context = context;

            if (_context.Authors.Count() == 0)
            {
                _context.Authors.Add(new Author {
                    firstName = "FirstName", lastName = "LastName"
                });
                _context.SaveChanges();
            }
        }
コード例 #2
0
        public AuthorsController(AuthorContext context)
        {
            this._context = context;

            if (this._context.AuthorsList.Count() == 0)
            {
                _context.AuthorsList.Add(new Author {
                    Name = "First Author"
                });
                _context.SaveChanges();
            }
        }
コード例 #3
0
 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;
 }
コード例 #4
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();
     }
 }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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;
        }
コード例 #9
0
 public BookTitlesController(AuthorContext context, IBookTitleRepository bookRepo)
 {
     _context  = context;
     _bookRepo = bookRepo;
 }
コード例 #10
0
 public GenresController(AuthorContext context)
 {
     _context = context;
 }
コード例 #11
0
 public BookTitleRepository(AuthorContext context)
 {
     _context = context;
 }
コード例 #12
0
 public Handler(AuthorContext context)
 {
     authorContext = context;
 }
コード例 #13
0
 public GenerateAuthors(AuthorContext autCtx, BookContext bookCtx)
 {
     this.autCtx  = autCtx;
     this.bookCtx = bookCtx;
 }
コード例 #14
0
 public ReviewsController(AuthorContext context, IReviewRepository reviewRepo, IBookTitleRepository bookTitleRepo)
 {
     _context       = context;
     _reviewRepo    = reviewRepo;
     _bookTitleRepo = bookTitleRepo;
 }
コード例 #15
0
        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();
        }
    }
}
コード例 #16
0
 public AuthorsController(AuthorContext context, IAuthorRepository authorRepo)
 {
     _context    = context;
     _authorRepo = authorRepo;
 }
コード例 #17
0
        // 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);
        }
コード例 #18
0
 public AuthorRepository(AuthorContext context)
 {
     _context = context;
 }
コード例 #19
0
 public Handler(AuthorContext authorContext)
 {
     this._authorContext = authorContext;
 }
コード例 #20
0
 public Manage(AuthorContext contexto, IMapper mapper)
 {
     _contexto = contexto;
     _mapper   = mapper;
 }
コード例 #21
0
 public AuthorRepository(AuthorContext authorContext)
 {
     this.authorContext = authorContext;
 }
コード例 #22
0
 public Handler(AuthorContext contexto, IMapper mapper)
 {
     this._context = contexto;
     this._mapper  = mapper;
 }
コード例 #23
0
 public Handler(AuthorContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
コード例 #24
0
 public ReviewRepository(AuthorContext context)
 {
     _context = context;
 }
コード例 #25
0
ファイル: AuthorController.cs プロジェクト: atiqahammed/lrn
 public AuthorController(AuthorContext context)
 {
     _context = context;
 }
コード例 #26
0
ファイル: New.cs プロジェクト: rrrago1/tiendaServicios
 public Manage(AuthorContext contexto)
 {
     _contexto = contexto;
 }
コード例 #27
0
 public GenerateNewBooks(BookContextNew newBookCtx, AuthorContext autCtx, BookContext bookCtx)
 {
     this.newBookCtx = newBookCtx;
     this.autCtx     = autCtx;
     this.bookCtx    = bookCtx;
 }
コード例 #28
0
 public AuthorEntityBinder(AuthorContext context)
 {
     _context = context;
 }
コード例 #29
0
 public AuthorRepository(IOptions <DatabaseSettings> options)
 {
     _context = new AuthorContext(options) ?? throw new ArgumentNullException(nameof(options));
 }
コード例 #30
0
 public BookTitleGenresController(AuthorContext context)
 {
     _context = context;
 }