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();
        }
        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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
 public void Add(Checkout newCheckout)
 {
     _DbContext.Add(newCheckout);
     _DbContext.SaveChanges();
 }
Ejemplo n.º 8
0
 public void Add(LibraryAsset newAsset)
 {
     _DbContext.Add(newAsset);
     _DbContext.SaveChanges();
 }