示例#1
0
        //Método para insertar categoría

        private void btInsert_Click(object sender, EventArgs e)
        {
            bool isValid = ValidateField();

            if (isValid)
            {
                CategoryForm category = new CategoryForm
                {
                    CategoryName        = this.txtInsertarCategoria.Text,
                    CategoryDescription = this.txtInsertarDescripcion.Text,
                    CategoryId          = Guid.NewGuid()
                };

                bool hasBeenInserted = BusinessCategory.InsertCategory(category);

                if (hasBeenInserted)
                {
                    RefreshDataGridView();
                    MessageBox.Show("Categoría insertada correctamente");
                    CleanFieldsInserted();
                }
                else
                {
                    MessageBox.Show("Error al insertar categoria");
                }
            }
        }
示例#2
0
        // Método para actualizar categoría

        private void button1_Click(object sender, EventArgs e)
        {
            bool isValid = ValidateFieldUpdate();

            if (!isValid)
            {
                return;
            }

            CategoryForm category = new CategoryForm
            {
                CategoryName        = this.txtCategoryName.Text,
                CategoryDescription = this.txtDescripcion.Text,
                CategoryId          = new Guid(this.lbId.Text),
            };
            bool isUpdated = BusinessCategory.UpdateCategory(category);

            if (isUpdated)
            {
                RefreshDataGridView();
                CleanFields();
                MessageBox.Show("Categoría actualizada correctamente");
            }
            else
            {
                MessageBox.Show("Ha ocurrido un error actualizando los campos de la categoría");
            }
        }
示例#3
0
        private ICategoryRepository GetInMemoryCategoryRepository()
        {
            var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider();

            var factory = serviceProvider.GetService <ILoggerFactory>();

            var _logger = factory.CreateLogger <CategoryRepository>();
            DbContextOptions <TriviaGameDbContext> options;

            options = new DbContextOptionsBuilder <TriviaGameDbContext>().UseInMemoryDatabase(databaseName: "TriviaGameDbContext").Options;
            TriviaGameDbContext _dbContext = new TriviaGameDbContext(options);

            _dbContext.Database.EnsureDeleted();
            DataAccess.Entities.Category cat1 = new DataAccess.Entities.Category()
            {
                Category1  = "Sports",
                CategoryId = 1,
            };
            DataAccess.Entities.Category cat2 = new DataAccess.Entities.Category()
            {
                Category1  = "Movies",
                CategoryId = 2,
            };

            _dbContext.Category.Add(cat1);

            _dbContext.Category.Add(cat2);
            _dbContext.Database.EnsureCreated();
            return(new CategoryRepository(_dbContext, _logger));
        }
 public DisplayCategory(DataAccess.Entities.Category category)
 {
     _category   = category;
     DisplayIcon = "Assets/Artifacts.png";
 }