private async void OkButton_Click(object sender, RoutedEventArgs e)
        {
            var entity = _id == 0 ? new Brand() : await _brandService.GetAsync(_id);

            entity.Name = BrandNameTextBox.Text;
            entity.Info = BrandInfoTextBox.Text;

            try
            {
                if (_id == 0)
                {
                    await _brandService.CreateAsync(entity);
                }
                else
                {
                    await _brandService.UpdateAsync(entity);
                }

                MainWindow.PublicBrandDataGrid.ItemsSource = await _brandService.GetAllAsync();

                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Server error");
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SaveBrand(Brand brand)
        {
            await _brandService.CreateAsync(brand);

            var result = (await _brandService.GetAllAsync()).Select(x => x.Name).ToList();

            return(Json(result));
        }
        public async Task CreateBrandAsync_ShouldCreateBrand()
        {
            var options = new DbContextOptionsBuilder <TechAndToolsDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateBrandAsync_ShouldCreateBrand")
                          .Options;

            TechAndToolsDbContext context      = new TechAndToolsDbContext(options);
            IBrandService         brandService = new BrandService(context);

            await brandService.CreateAsync(new BrandServiceModel { Name = "name1", LogoUrl = "Logo1", OfficialSite = "Site1" });

            await brandService.CreateAsync(new BrandServiceModel { Name = "name2", LogoUrl = "Logo2", OfficialSite = "Site2" });

            int expectedResult = 2;
            int actualResult   = context.Brands.Count();

            Assert.Equal(expectedResult, actualResult);
        }