public async Task <ActionResult <Company> > Put(int id, [FromBody] CompanyDTO request)
        {
            var company = await _service.GetByIdAsync(id);

            await _service.DeletePrefixesByCompanyAsync(company);

            company.Name     = request.Name;
            company.Prefixes = request.Prefixes.Select(p => new Prefix {
                Number = p.Number
            }).ToList();

            _db.Entry(company).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            return(Ok(company));
        }
Exemplo n.º 2
0
        public async Task TestGetByIdCompany()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var companyRepository = new EfDeletableEntityRepository <Company>(new ApplicationDbContext(options.Options));
            var hotelRepository   = new EfDeletableEntityRepository <Hotel>(new ApplicationDbContext(options.Options));

            await companyRepository.AddAsync(new Company { Id = 1, Bulstat = "131071587" });

            await companyRepository.AddAsync(new Company { Id = 2, Bulstat = "131071589" });

            await companyRepository.SaveChangesAsync();

            var companyService = new CompaniesService(companyRepository, hotelRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyTestCompany).Assembly);
            var company = await companyService.GetByIdAsync <MyTestCompany>(1);

            Assert.Equal("131071587", company.Bulstat);
        }