public void Start()
        {
            /* validace entit jako takových */
            Article article = new Article
            {
                AuthorEmail = "mirek.cz"
            };

            ICollection<ValidationResult> results = new List<ValidationResult>();
            bool isValid = Validator.TryValidateObject(article, new ValidationContext(article), results, true);

            if (!isValid)
            {
                foreach (var validationResult in results)
                {
                    Console.WriteLine("Property: {0}, Error {1}", string.Join(", ", validationResult.MemberNames),
                        validationResult.ErrorMessage);
                }
            }

            Console.WriteLine("**************");

            /* explicitní validace nad contextem */
            BookStoreContext context = new BookStoreContext();
            context.Books.Add(new Book() {});
            context.Books.Add(new Book() {});

            foreach (var validationResults in context.GetValidationErrors())
            {
                foreach (var error in validationResults.ValidationErrors)
                {
                    Console.WriteLine("Property: {0}, Error {1}", error.PropertyName, error.ErrorMessage);
                }
            }
        }
 public ActionResult Index()
 {
     using (var db = new BookStoreContext("BookStoreConnectionString"))
     {
         return View(db.Books.ToList());
     }
 }
 public ActionResult Add(Book book)
 {
     using (var db = new BookStoreContext("BookStoreConnectionString"))
     {
         db.Books.Add(book);
         db.SaveChanges();
     }
     return View(book);
 }
        public void Start()
        {
            BookStoreContext context1 = new BookStoreContext();
            BookStoreContext context2 = new BookStoreContext();

            var book1 = context1.Books.Find(2);
            book1.Title = "O pejskách a kočičkách AH";

            var book2 = context2.Books.Find(2);
            book2.Title = "Nový pejsci a kočičky PO";

            context2.SaveChanges();
            context1.SaveChanges();

            context1.Dispose();
            context2.Dispose();
        }
Example #5
0
        static void Main(string[] args)
        {
            using(var db = new BookStoreContext())
            {
                var book = db.Books.Add(new Book()
                {
                    Title = "Intro C# Book",
                    Price = 10.0f,
                    Autor = new Autor()
                    {
                        FirstName = "Svetlin",
                        LastName = "Nakov"
                    },
                    Category = Categories.Software,
                    ReleaseDate = new DateTime(2010, 10, 10)
                });

                db.SaveChanges();
            }
        }
Example #6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var searchItem = SearchByBox.SelectedValue.ToString();
            var searchText = searchBox.Text;

            switch (searchItem)
            {
            case "Books":
                using (var dbContext = new BookStoreContext())
                {
                    var query =
                        from book in dbContext.Books
                        join author in dbContext.Authors on book.AuthorRefId equals author.Id
                        join genre in dbContext.Genres on book.GenreRefId equals genre.Id
                        join category in dbContext.Categories on book.CategoryRefId equals category.Id
                        join serie in dbContext.Series on book.SerieRefId equals serie.Id
                        where book.Name.Contains(searchText)
                        select new
                    {
                        Id                  = book.Id,
                        Book__Name          = book.Name,
                        Genre__Name         = genre.Name,
                        Price               = book.Price,
                        Category            = category.Name,
                        Serie               = serie.Name,
                        Author__First__Name = author.Firstname,
                        Author__Last__Name  = author.Lastname
                    };

                    DataGrid1.ItemsSource = query.ToList();
                }
                break;

            case "Authors":
                using (var dbContext = new BookStoreContext())
                {
                    var query =
                        from book in dbContext.Books
                        join author in dbContext.Authors on book.AuthorRefId equals author.Id
                        join genre in dbContext.Genres on book.GenreRefId equals genre.Id
                        join category in dbContext.Categories on book.CategoryRefId equals category.Id
                        join serie in dbContext.Series on book.SerieRefId equals serie.Id
                        where author.Firstname.Contains(searchText) || author.Lastname.Contains(searchText)
                        select new
                    {
                        Id                  = book.Id,
                        Book__Name          = book.Name,
                        Genre__Name         = genre.Name,
                        Price               = book.Price,
                        Category            = category.Name,
                        Serie               = serie.Name,
                        Author__First__Name = author.Firstname,
                        Author__Last__Name  = author.Lastname
                    };

                    DataGrid1.ItemsSource = query.ToList();
                }
                break;

            case "Genres":
                using (var dbContext = new BookStoreContext())
                {
                    var query =
                        from book in dbContext.Books
                        join author in dbContext.Authors on book.AuthorRefId equals author.Id
                        join genre in dbContext.Genres on book.GenreRefId equals genre.Id
                        join category in dbContext.Categories on book.CategoryRefId equals category.Id
                        join serie in dbContext.Series on book.SerieRefId equals serie.Id
                        where genre.Name.Contains(searchText)
                        select new
                    {
                        Id                  = book.Id,
                        Book__Name          = book.Name,
                        Genre__Name         = genre.Name,
                        Price               = book.Price,
                        Category            = category.Name,
                        Serie               = serie.Name,
                        Author__First__Name = author.Firstname,
                        Author__Last__Name  = author.Lastname
                    };

                    DataGrid1.ItemsSource = query.ToList();
                }
                break;

            case "Categories":
                using (var dbContext = new BookStoreContext())
                {
                    var query =
                        from book in dbContext.Books
                        join author in dbContext.Authors on book.AuthorRefId equals author.Id
                        join genre in dbContext.Genres on book.GenreRefId equals genre.Id
                        join category in dbContext.Categories on book.CategoryRefId equals category.Id
                        join serie in dbContext.Series on book.SerieRefId equals serie.Id
                        where category.Name.Contains(searchText)
                        select new
                    {
                        Id                  = book.Id,
                        Book__Name          = book.Name,
                        Genre__Name         = genre.Name,
                        Price               = book.Price,
                        Category            = category.Name,
                        Serie               = serie.Name,
                        Author__First__Name = author.Firstname,
                        Author__Last__Name  = author.Lastname
                    };

                    DataGrid1.ItemsSource = query.ToList();
                }
                break;

            case "Series":
                using (var dbContext = new BookStoreContext())
                {
                    var query =
                        from book in dbContext.Books
                        join author in dbContext.Authors on book.AuthorRefId equals author.Id
                        join genre in dbContext.Genres on book.GenreRefId equals genre.Id
                        join category in dbContext.Categories on book.CategoryRefId equals category.Id
                        join serie in dbContext.Series on book.SerieRefId equals serie.Id
                        where serie.Name.Contains(searchText)
                        select new
                    {
                        Id                  = book.Id,
                        Book__Name          = book.Name,
                        Genre__Name         = genre.Name,
                        Price               = book.Price,
                        Category            = category.Name,
                        Serie               = serie.Name,
                        Author__First__Name = author.Firstname,
                        Author__Last__Name  = author.Lastname
                    };

                    DataGrid1.ItemsSource = query.ToList();
                }
                break;

            default:
                break;
            }
        }
Example #7
0
 public UnitOfWork(BookStoreContext context)
 {
     _context = context;
 }
Example #8
0
 public Handler(BookStoreContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #9
0
 public HomeController(BookStoreContext context)
 {
     _context = context;
 }
Example #10
0
 public ProductRL(BookStoreContext context)
 {
     this.context = context;
 }
 public TransactionExamples(BookStoreContext context)
 {
     this.context = context;
 }
Example #12
0
 public BookRepository(BookStoreContext storeContext)
 {
     _bookStoreContext = storeContext;
 }
 public PredicateBuilderExamples(BookStoreContext context)
 {
     this.context = context;
 }
Example #14
0
 public XmlParser(BookStoreContext db, string xmlFilePath)
 {
     this.XmlFilePath = xmlFilePath;
     this.db = db;
 }
 public MethodSyntaxExamples(BookStoreContext context)
 {
     this.context = context;
 }
 public QuerySyntaxExamples(BookStoreContext context)
 {
     this.context = context;
 }
 public AuthorsRepository(BookStoreContext context, ILogger <BookStoreContext> logger) : base(context, logger)
 {
     this.logger = logger;
 }
Example #18
0
 public ReviewsController(BookStoreContext context)
 {
     _context = context;
 }
Example #19
0
 public BookRepository(BookStoreContext _context)
 {
     context = _context;
 }
 public LanguageRepository(BookStoreContext context)
 {
     _context = context;
 }
 public CustomerRepository(BookStoreContext context) : base(context)
 {
 }
 public ModificationExamples(BookStoreContext context)
 {
     this.context = context;
 }
Example #23
0
 public CartBAL()
 {
     context = new BookStoreContext();
 }
Example #24
0
 public ReviewsController(BookStoreContext context)
 {
     _reviewBusiness = new ReviewBusiness(context);
 }
Example #25
0
 public EfGetProductsQuery(BookStoreContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public BookData(BookStoreContext context)
 {
     _context = context;
 }
Example #27
0
 public BaseService(BookStoreContext context)
 {
     _repository = new BaseRepository <T>(context);
 }
Example #28
0
 public UserBusiness(BookStoreContext context)
 {
     _userData = new UserData(context);
 }
Example #29
0
 public AuthorContactsController(BookStoreContext context)
 {
     _context = context;
 }
Example #30
0
 public LineItemValidator(BookStoreContext context)
 {
     this.dbContext = context ?? throw new ArgumentNullException(nameof(dbContext));
     RuleFor(r => r.BookId).Must(BookExists).WithMessage("Book not found");
 }
 public JournalRepository(BookStoreContext context)
 {
     _context = context;
 }
 public BookRepository(BookStoreContext dbContext) : base(dbContext)
 {
 }
Example #33
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            string pathToJsonFile = string.Empty;

            // Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog()
            {
                Filter = "json files (*.json)|*.json" // Filter files by extension
            };
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                pathToJsonFile = dlg.FileName;
            }

            List <Book> books = new List <Book>();

            using (StreamReader r = new StreamReader(pathToJsonFile))
            {
                string json = r.ReadToEnd();
                books = JsonConvert.DeserializeObject <List <Book> >(json);
            }

            Book     tempBook     = new Book();
            Author   tempAuthor   = new Author();
            Genre    tempGenre    = new Genre();
            Category tempCategory = new Category();
            Series   tempSeries   = new Series();

            foreach (var book in books)
            {
                tempAuthor.Firstname = book.Author.Firstname;
                tempAuthor.Lastname  = book.Author.Lastname;
                tempGenre.Name       = book.Genre.Name;
                tempCategory.Name    = book.Category.Name;
                tempSeries.Name      = book.Serie.Name;
                tempBook.Name        = book.Name;
                tempBook.Price       = book.Price;
                tempBook.Serie       = book.Serie;
                tempBook.Category    = tempBook.Category;


                using (var dbContext = new BookStoreContext())
                {
                    dbContext.Series.Add(tempSeries);
                    dbContext.Categories.Add(tempCategory);
                    dbContext.Genres.Add(tempGenre);
                    dbContext.Authors.Add(tempAuthor);
                    dbContext.Books.Add(tempBook);
                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (DbEntityValidationException ea)
                    {
                        foreach (var eve in ea.EntityValidationErrors)
                        {
                            searchBox.Text = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                           eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                searchBox.Text += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                                ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                    }
                }
            }
        }
Example #34
0
 public BooksController(BookStoreContext context)
 {
     _bookBusiness = new BookBusiness(context);
 }
Example #35
0
 public BookCategoriesController(BookStoreContext context)
 {
     _context = context;
 }
Example #36
0
 public UsersController(BookStoreContext context)
 {
     _userBusiness = new UserBusiness(context);
 }
 public BookRepository(BookStoreContext context)
 {
     _context = context;
 }
Example #38
0
 public AuthorRepository(BookStoreContext context) : base(context)
 {
 }
Example #39
0
 public BookRepository(BookStoreContext context) : base(context)
 {
 }
Example #40
0
 public AuthorDataManager(BookStoreContext storeContext)
 {
     _bookStoreContext = storeContext;
 }
 public EntityStateExamples(BookStoreContext context)
 {
     this.context = context;
 }
Example #42
0
 public ReadRepositoryUnitTest(string databaseName)
 {
     bookStoreContext     = BookStoreContext.NewDatabaseInMemory(databaseName);
     bookReadRepository   = new DefaultReadRepository <BookStoreContext, Book>(bookStoreContext);
     authorReadRepository = new DefaultReadRepository <BookStoreContext, Author>(bookStoreContext);
 }