protected void SaveCreate_Click(object sender, EventArgs e)
        {
            var name = (CategoryCreate.FindControl("CreateCategory") as TextBox).Text;

            if (string.IsNullOrEmpty(name))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title cannot be empty");
                return;
            }
            else if (name.Length < 5 || name.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title must be between 5 and 50 symbols");
                return;
            }

            LibrarySystemDbContext context = new LibrarySystemDbContext();

            context.Categories.Add(new Category
            {
                Name = name,
            });

            context.SaveChanges();

            CategoryCreate.DataSource = null;
            CategoryCreate.DataBind();
            CategoriesGrid.DataBind();
        }
        protected void SaveEdit_Click(object sender, EventArgs e)
        {
            var newName = (CategoryDetails.FindControl("EditCategory") as TextBox).Text;

            if (string.IsNullOrEmpty(newName))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title cannot be empty");
                return;
            }
            else if (newName.Length < 5 || newName.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title must be between 5 and 50 symbols");
                return;
            }

            var id = int.Parse(CategoryDetails.DataKey.Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var category = data.Categories.FirstOrDefault(x => x.Id == id);

            category.Name = newName;

            data.SaveChanges();

            CategoryDetails.DataSource = null;
            CategoryDetails.DataBind();
            CategoriesGrid.DataBind();
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var segments = Request.GetFriendlyUrlSegments();

            LibrarySystemDbContext data = new LibrarySystemDbContext();

            if (segments.Count == 0)
            {
                var results = data.Books.ToList();

                ResultsRepeater.DataSource = results;
                ResultsRepeater.DataBind();
            }
            else
            {
                var query = segments[0];

                if (query.Length > 100)
                {
                    ErrorSuccessNotifier.AddErrorMessage("Search query cannot be more than 100 characters");
                    Response.Redirect("~/");
                }

                var results = data.Books
                              .Where(x => x.Title.Contains(query) || x.Authors.Contains(query))
                              .OrderBy(x => x.Title)
                              .ThenBy(x => x.Authors)
                              .ToList();

                ResultsRepeater.DataSource = results;
                ResultsRepeater.DataBind();
            }
        }
Example #4
0
        public IQueryable <WebFormsTemplate.Models.Category> AllCategoriesList_GetData()
        {
            LibrarySystemDbContext data = new LibrarySystemDbContext();

            var categories = data.Categories.OrderBy(x => x.Name);

            return(categories);
        }
Example #5
0
        public IQueryable <Category> BooksCategoris_GetData()
        {
            LibrarySystemDbContext data = new LibrarySystemDbContext();

            var categories = data.Categories.OrderBy(cat => cat.Id);

            return(categories);
        }
        public GenericRepository(LibrarySystemDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("An instance of DbContext is required to use this repository.", "context");
            }

            this.Context = context;
            this.DbSet   = this.Context.Set <T>();
        }
        protected void Edit_Click(object sender, EventArgs e)
        {
            GridViewRow row        = ((Button)sender).Parent.Parent as GridViewRow;
            var         categoryId = int.Parse(CategoriesGrid.DataKeys[row.RowIndex].Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var category = data.Categories.FirstOrDefault(x => x.Id == categoryId);

            CategoryDetails.DataSource = new List <Category> {
                category
            };
            CategoryDetails.DataBind();
        }
Example #8
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            GridViewRow row    = ((Button)sender).Parent.Parent as GridViewRow;
            var         bookId = int.Parse(BooksGrid.DataKeys[row.RowIndex].Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var book = data.Books.FirstOrDefault(x => x.Id == bookId);

            BookDelete.DataSource = new List <Book> {
                book
            };
            BookDelete.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var segments = Request.GetFriendlyUrlSegments();
            var id       = int.Parse(segments[0]);

            LibrarySystemDbContext data = new LibrarySystemDbContext();

            var book = data.Books.FirstOrDefault(x => x.Id == id);

            BookDetail.DataSource = new List <Book> {
                book
            };
            BookDetail.DataBind();
        }
Example #10
0
        protected void Edit_Click(object sender, EventArgs e)
        {
            GridViewRow row    = ((Button)sender).Parent.Parent as GridViewRow;
            var         bookId = int.Parse(BooksGrid.DataKeys[row.RowIndex].Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var book = data.Books.FirstOrDefault(x => x.Id == bookId);

            BookEdit.DataSource = new List <Book> {
                book
            };
            BookEdit.DataBind();

            (BookEdit.FindControl("BookCategory") as DropDownList).SelectedValue = book.CategoryId.ToString();
        }
Example #11
0
        protected void SaveDelete_Click(object sender, EventArgs e)
        {
            var id = int.Parse(BookDelete.DataKey.Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var book = data.Books.FirstOrDefault(x => x.Id == id);

            data.Books.Remove(book);

            data.SaveChanges();

            BookDelete.DataSource = null;
            BookDelete.DataBind();
            BooksGrid.DataBind();
        }
        protected void SaveDelete_Click(object sender, EventArgs e)
        {
            var id = int.Parse(CategoryDelete.DataKey.Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var category = data.Categories.FirstOrDefault(x => x.Id == id);

            data.Books.RemoveRange(category.Books);
            data.Categories.Remove(category);

            data.SaveChanges();

            CategoryDelete.DataSource = null;
            CategoryDelete.DataBind();
            CategoriesGrid.DataBind();
        }
Example #13
0
        public IQueryable <WebFormsTemplate.Models.BookViewModel> BooksGrid_GetData()
        {
            LibrarySystemDbContext data = new LibrarySystemDbContext();

            var books = data.Books.OrderBy(b => b.Id).Select(x => new BookViewModel
            {
                Id           = x.Id,
                Title        = x.Title,
                Authors      = x.Authors,
                Description  = x.Description,
                ISBN         = x.ISBN,
                WebSite      = x.WebSite,
                CategoryName = x.Category.Name,
            });

            return(books);
        }
Example #14
0
        private void SeedAdmin(LibrarySystemDbContext context)
        {
            const string AdministratorUserName = "******";
            const string AdministratorPassword = "******";

            if (!context.Roles.Any())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);
                var role        = new IdentityRole {
                    Name = GlobalConstants.AdminRole
                };
                roleManager.Create(role);

                var userStore   = new UserStore <User>(context);
                var userManager = new UserManager <User>(userStore);
                var user        = new User {
                    UserName = AdministratorUserName, Email = AdministratorUserName, EmailConfirmed = true
                };
                userManager.Create(user, AdministratorPassword);

                userManager.AddToRole(user.Id, GlobalConstants.AdminRole);
            }
        }
Example #15
0
 public LibraryCardService(LibrarySystemDbContext DbContext)
 {
     _DbContext = DbContext;
 }
Example #16
0
        protected void SaveEdit_Click(object sender, EventArgs e)
        {
            var title       = (BookEdit.FindControl("BookTitle") as TextBox).Text;
            var authors     = (BookEdit.FindControl("BookAuthors") as TextBox).Text;
            var ISBN        = (BookEdit.FindControl("BookIsbn") as TextBox).Text;
            var site        = (BookEdit.FindControl("BookSite") as TextBox).Text;
            var description = (BookEdit.FindControl("BookDescription") as TextBox).Text;
            var categoryId  = int.Parse((BookEdit.FindControl("BookCategory") as DropDownList).SelectedValue);

            if (string.IsNullOrEmpty(title))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title cannot be empty");
                return;
            }
            else if (title.Length < 5 || title.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title must be between 5 and 50 symbols");
                return;
            }
            else if (string.IsNullOrEmpty(authors))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty");
                return;
            }
            else if (authors.Length < 5 || authors.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors must be between 5 and 50 symbols");
                return;
            }
            else if (ISBN.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols");
                return;
            }
            else if (site.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols");
                return;
            }
            else if (description.Length > 2000)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Description must be less than 2000 symbols");
                return;
            }
            else if (categoryId == -1 || categoryId == null)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty");
                return;
            }

            var id = int.Parse(BookEdit.DataKey.Value.ToString());

            LibrarySystemDbContext data = new LibrarySystemDbContext();
            var book = data.Books.FirstOrDefault(x => x.Id == id);

            book.Title       = title;
            book.Authors     = authors;
            book.ISBN        = ISBN;
            book.WebSite     = site;
            book.Description = description;
            book.CategoryId  = categoryId;

            data.SaveChanges();

            BookEdit.DataSource = null;
            BookEdit.DataBind();
            BooksGrid.DataBind();
        }
Example #17
0
        private void SeedSampleData(LibrarySystemDbContext context)
        {
            if (!context.Books.Any())
            {
                Author markSeemann = new Author {
                    FirstName = "Mark", LastName = "Seemann"
                };

                Author royOsherove = new Author {
                    FirstName = "Roy", LastName = "Osherove"
                };

                Author martinFowler = new Author {
                    FirstName = "Martin", LastName = "Fowler"
                };

                Genre software = new Genre {
                    Name = "Software"
                };

                Genre technical = new Genre {
                    Name = "Technical"
                };

                Genre programming = new Genre {
                    Name = "Programming"
                };

                Book theBook = new Book
                {
                    Title            = "Dependency Injection in .NET",
                    ISBN             = "9781935182504",
                    Description      = @"Dependency Injection in .NET introduces DI and provides a practical guide for applying it in .NET applications.
                                    The book presents the core patterns in plain C#, so you'll fully understand how DI works. Then you'll learn to integrate DI
                                    with standard Microsoft technologies like ASP.NET MVC, and to use DI frameworks like StructureMap, Castle Windsor, and Unity.
                                    By the end of the book, you'll be comfortable applying this powerful technique in your everyday .NET development.",
                    PageCount        = 584,
                    YearOfPublishing = 2011,
                    Authors          = new HashSet <Author>()
                    {
                        markSeemann
                    },
                    Genres = new HashSet <Genre>()
                    {
                        software
                    }
                };

                Book theArtOfUnitTesting = new Book
                {
                    Title            = "The Art of Unit Testing",
                    ISBN             = "9781933988276",
                    Description      = @"The Art of Unit Testing builds on top of what's already been written about this important topic. It guides you step by step
                                    from simple tests to tests that are maintainable, readable, and trustworthy. It covers advanced subjects like mocks, stubs,
                                    and frameworks such as Typemock Isolator and Rhino Mocks. And you'll learn about advanced test patterns and organization,
                                    working with legacy code and even untestable code. The book discusses tools you need when testing databases and other technologies.",
                    PageCount        = 320,
                    YearOfPublishing = 2009,
                    Authors          = new HashSet <Author>()
                    {
                        royOsherove
                    },
                    Genres = new HashSet <Genre>()
                    {
                        software,
                        technical
                    }
                };

                Book patternsOfEnterpriseAppArchitecture = context.Books
                                                           .Where(b => b.ISBN == "9780321127426")
                                                           .SingleOrDefault() ?? new Book
                {
                    Title            = "Patterns of Enterprise Application Architecture",
                    ISBN             = "9780321127426",
                    Description      = @"These pages are a brief overview of each of the patterns in P of EAA. They aren't intended to stand alone, but merely as a quick
                                    aide-memoire for those familiar with them, and a handy link if you want to refer to one online. In the future I may add some
                                    post-publication comments into the material here, but we'll see how that works out.",
                    PageCount        = 533,
                    YearOfPublishing = 2003,
                    Authors          = new HashSet <Author>()
                    {
                        martinFowler
                    },
                    Genres = new HashSet <Genre>()
                    {
                        software,
                        programming
                    },
                };
                context.Books.Add(theBook);
                context.Books.Add(theArtOfUnitTesting);
                context.Books.Add(patternsOfEnterpriseAppArchitecture);
            }
        }
 public UowData(LibrarySystemDbContext context)
 {
     this.context = context;
 }
Example #19
0
 public BasePage()
 {
     this.data = new LibrarySystemDbContext();
 }
 public HoldService(LibrarySystemDbContext DbContext)
 {
     _DbContext = DbContext;
 }
Example #21
0
        public EfUnitOfWork(LibrarySystemDbContext context)
        {
            Guard.WhenArgument(context, "Unit of work dbcontext").IsNull().Throw();

            this.context = context;
        }
Example #22
0
        public EfRepostory(LibrarySystemDbContext context)
        {
            Guard.WhenArgument(context, "EfRepostory dbcontext").IsNull().Throw();

            this.context = context;
        }
 public LibraryPatronService(LibrarySystemDbContext DbContext)
 {
     _DbContext = DbContext;
 }
Example #24
0
 public LibraryCheckoutService(LibrarySystemDbContext DbContext)
 {
     _DbContext = DbContext;
 }
Example #25
0
 public LibraryBranchService(LibrarySystemDbContext DbContext)
 {
     _DbContext = DbContext;
 }
Example #26
0
        protected void SaveCreate_Click(object sender, EventArgs e)
        {
            var title       = (BookCreate.FindControl("BookTitle") as TextBox).Text;
            var authors     = (BookCreate.FindControl("BookAuthors") as TextBox).Text;
            var ISBN        = (BookCreate.FindControl("BookIsbn") as TextBox).Text;
            var site        = (BookCreate.FindControl("BookSite") as TextBox).Text;
            var description = (BookCreate.FindControl("BookDescription") as TextBox).Text;
            var categoryId  = int.Parse((BookCreate.FindControl("BookCategory") as DropDownList).SelectedValue);

            if (string.IsNullOrEmpty(title))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title cannot be empty");
                return;
            }
            else if (title.Length < 5 || title.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Title must be between 5 and 50 symbols");
                return;
            }
            else if (string.IsNullOrEmpty(authors))
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty");
                return;
            }
            else if (authors.Length < 5 || authors.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors must be between 5 and 50 symbols");
                return;
            }
            else if (ISBN.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols");
                return;
            }
            else if (site.Length > 50)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("ISBN must be less than 50 symbols");
                return;
            }
            else if (description.Length > 2000)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Description must be less than 2000 symbols");
                return;
            }
            else if (categoryId == -1)
            {
                Error_Handler_Control.ErrorSuccessNotifier.AddErrorMessage("Authors cannot be empty");
                return;
            }

            LibrarySystemDbContext context = new LibrarySystemDbContext();

            context.Books.Add(new Book
            {
                Title       = title,
                Authors     = authors,
                ISBN        = ISBN,
                WebSite     = site,
                Description = description,
                CategoryId  = categoryId
            });

            context.SaveChanges();

            BookCreate.DataSource = null;
            BookCreate.DataBind();
            BooksGrid.DataBind();
        }
Example #27
0
 public AssetService(LibrarySystemDbContext DbContext)
 {
     _DbContext = DbContext;
 }