Esempio n. 1
0
        public async Task <ResponseInsertRegion> Handle(ParamInsertRegion request, CancellationToken cancellationToken)
        {
            try
            {
                if (!request.Region.IsValid)
                {
                    return(new ResponseInsertRegion(
                               HttpStatusCode.BadRequest,
                               request.Region.Notifications));
                }

                _regionRepository.Create(
                    new Domain.Models.Region(
                        latitude: request.Region.Latitude,
                        longitude: request.Region.Longitude,
                        description: request.Region.Description));

                await _unitOfWork.Commit();

                return(new ResponseInsertRegion(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
0
        public async Task <ServiceResponse <Region> > Create(AddRegionRequest request)
        {
            try
            {
                var country = await _countryService.FindByIdInclusive(request.CountryId, x => x.Include(p => p.Regions));

                if (!country.Success)
                {
                    return(new ServiceResponse <Region>($"The country does not exist"));
                }

                if (country.Data.Regions.Count > 0 && country.Data.Regions.Any(x => x.Name.ToLower().Equals(request.Name.ToLower())))
                {
                    return(new ServiceResponse <Region>($"The region with name {request.Name} already exist exist"));
                }

                var region = new Region
                {
                    Code        = $"RGN{_codeGenService.GenerateRandomString(8)}",
                    CountryId   = request.CountryId,
                    Name        = request.Name,
                    Description = request.Description
                };


                await _regionRepository.Create(region);

                return(new ServiceResponse <Region>(region));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Region>($"An Error Occured while creating a region Resource. {ex.Message}"));
            }
        }
Esempio n. 3
0
        public async Task ComUmaDiferenca()
        {
            var first = regionRepository.Get(1);

            regionRepository.Delete(first);
            regionRepository.Create(new Region(1, "V", "Vorte"));
            var result = await regionDiffServices.Get();

            Assert.NotEmpty(result.Diffs);
        }
Esempio n. 4
0
        public RegionDiffServicesTests()
        {
            httpClient           = new HttpClient();
            regionIbgeRepository = new RegionIbgeRepository(httpClient);
            context          = new FakeContext();
            regionRepository = new RegionRepository(context);
            context.Region.RemoveRange(regionRepository.Get());
            local = new List <Region>()
            {
                new Region(1, "N", "Norte"),
                new Region(2, "NE", "Nordeste"),
                new Region(3, "SE", "Sudeste"),
                new Region(4, "S", "Sul"),
                new Region(5, "CO", "Centro-Oeste")
            };
            local.ForEach(x => regionRepository.Create(x));


            regionDiffServices = new RegionDiffServices(regionIbgeRepository, regionRepository);
        }
Esempio n. 5
0
 /// <summary>
 /// Used to create Region
 /// </summary>
 /// <param name="region">holds the region data</param>
 public async Task Create(Region region)
 {
     await _regionRepository.Create(region);
 }