Exemplo n.º 1
0
        public ManufacturerDetailModel GetById(Guid id)
        {
            var categoryEntity = manufacturerRepository.GetById(id);

            categoryEntity.Product = productRepository.GetByManufacturerId(id);
            return(mapper.Map <ManufacturerDetailModel>(categoryEntity));
        }
Exemplo n.º 2
0
        public List <ProductListModel> GetAll()
        {
            var productEntityList = productRepository.GetAll();

            foreach (var productEntity in productEntityList)
            {
                productEntity.Manufacturer = manufacturerRepository.GetById(productEntity.ManufacturerId);
                productEntity.Category     = categoryRepository.GetById(productEntity.CategoryId);
            }
            return(mapper.Map <List <ProductListModel> >(productEntityList));
        }
        public IActionResult DeleteConfirmed(int id)
        {
            var manufacturer = _manufacturerRepository.GetById(id);

            _manufacturerRepository.Remove(manufacturer);
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 4
0
        public void GetById_Exception_ShouldReturnInternalServerErrorStatusCodeAndNull()
        {
            Mock <ApplicationDbContext> mock =
                new Mock <ApplicationDbContext>(new DbContextOptions <ApplicationDbContext>());

            mock.Object.Manufacturers = GetQueryableMockDbSet <Manufacturer>();

            using (var manufacturersRepository = new ManufacturerRepository(mock.Object))
            {
                var result = manufacturersRepository.GetById(4);

                Assert.NotNull(result);
                Assert.Null(result.Data);
                Assert.Equal((int)HttpStatusCode.InternalServerError, result.StatusCode);
            }
        }
Exemplo n.º 5
0
        public void GetById_IdDoesNotExistInRepo_ShouldReturnNotFoundStatusCodeAndNull()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("50CE0FB7-45C0-4656-B6A8-C61C59157DB0").Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.AddRange(_manufacturers);
                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(options))
                using (var manufacturersRepository = new ManufacturerRepository(context))
                {
                    var result = manufacturersRepository.GetById(4);

                    Assert.NotNull(result);
                    Assert.Null(result.Data);
                    Assert.Equal((int)HttpStatusCode.NotFound, result.StatusCode);
                }
        }
Exemplo n.º 6
0
        public void GetById_IdExistsInRepo_ShouldReturnOkStatusCodeAndManufacturer()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("25D51D2B-3A99-4A41-8D90-0EBBA7CDEF76").Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.AddRange(_manufacturers);
                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(options))
                using (var manufacturersRepository = new ManufacturerRepository(context))
                {
                    var result = manufacturersRepository.GetById(1);

                    Assert.NotNull(result);
                    Assert.NotNull(result.Data);
                    Assert.Equal((int)HttpStatusCode.OK, result.StatusCode);
                }
        }
Exemplo n.º 7
0
        public ManufacturerModel GetById(int id)
        {
            var manufacturer      = manufacturerRepository.GetById(id);
            var manufactererModel = new ManufacturerModel
            {
                Name    = manufacturer.Name,
                Details = manufacturer.Details.Select(x => new DetailModel
                {
                    Price          = x.Price,
                    CarId          = x.CarId,
                    ManufacturerId = x.ManufacturerId,
                    TypeId         = x.TypeId
                }).ToList(),
                Cars = manufacturer.Cars.Select(x => new CarModel
                {
                    Model          = x.Model,
                    ManufacturerId = x.ManufacturerId
                }).ToList()
            };

            return(manufactererModel);
        }
 protected async override Task OnInitializedAsync()
 {
     _manufacturer = await ManufacturerRepository.GetById(Id);
 }