예제 #1
0
        //[HttpPost]
        //public async Task AddFile(IFormFileCollection uploads)
        //{
        //    await _fileService.Save(uploads);
        //}

        public async Task <IActionResult> AddProduct()
        {
            var categories = await _categoryService.GetAllAsync();

            var brands = await _brandService.GetAllAsync();

            ViewBag.Categories = categories.Select(x => x.Title);
            ViewBag.Brands     = brands.Select(x => x.Name);
            return(View());
        }
예제 #2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;

            var attempts = 0;
            var total    = 5;

            while (attempts < total)
            {
                try
                {
                    var equipments = await _equipmentService.GetAllAsync();

                    EquipmentDataGrid.ItemsSource = equipments;
                    PublicEquipDataGrid           = EquipmentDataGrid;

                    var brands = await _brandService.GetAllAsync();

                    BrandDataGrid.ItemsSource = brands;
                    PublicBrandDataGrid       = BrandDataGrid;

                    var tools = await _toolService.GetAllAsync();

                    ToolDataGrid.ItemsSource = tools;
                    PublicToolDataGrid       = ToolDataGrid;

                    IsEnabled = true;

                    break;
                }
                catch (Exception)
                {
                    attempts++;
                    Thread.Sleep(1000);
                }
            }

            if (attempts == total)
            {
                MessageBox.Show(
                    "Сервер недоступен",
                    "Ошибка",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                    );

                Environment.Exit(1);
            }
        }
        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");
            }
        }
예제 #4
0
        public async Task Getting_All_Brands_Returns_First_Page_Only()
        {
            var brands = GetBrandsForPaging();

            foreach (var brand in brands)
            {
                await _catalogDbContext.Brands.AddAsync(brand);
            }

            await _catalogDbContext.SaveChangesAsync();

            var result = await _brandService.GetAllAsync(5, 0);

            Assert.That(result.Count, Is.EqualTo(5));
            Assert.That(result.First().Id, Is.EqualTo(1));
            Assert.That(result.Last().Id, Is.EqualTo(5));
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var brands = await _brandService.GetAllAsync();

            BrandComboBox.ItemsSource = brands;
            var tools = await _toolService.GetAllAsync();

            ToolComboBox.ItemsSource = tools;
        }
예제 #6
0
        public async Task BrandService_GetAllBrands_ListOfBrandsWithOneBrand()
        {
            var listToReturn = new List <Brand> {
                new Brand()
            };
            var config       = new MapperConfiguration(cfg => cfg.CreateMap <Brand, BrandDto>());
            var repo         = A.Fake <IBrandRepository>();
            var brandservice = new BrandService(repo, config.CreateMapper());

            A.CallTo(() => repo.GetAllAsync()).Returns(listToReturn);
            var result = await brandservice.GetAllAsync();

            Assert.That(result, Has.Exactly(1).Items);
        }