Exemplo n.º 1
0
        public IActionResult CreateRegion([FromBody] RegionCreateDto createRegion)
        {
            if (createRegion == null)
            {
                return(BadRequest());
            }
            if (createRegion.Description == null || createRegion.Name == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (_transActionRepo.RegionExists(createRegion.Name))
            {
                return(BadRequest());
            }

            var newRegion = Mapper.Map <TraRegion>(createRegion);

            _transActionRepo.CreateRegion(newRegion);


            if (!_transActionRepo.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdPointOfInterestToReturn = Mapper.Map <RegionDto>(newRegion);

            return(CreatedAtRoute("GetThatRegion", new { id = createdPointOfInterestToReturn.RegionId }, createdPointOfInterestToReturn));
        }
Exemplo n.º 2
0
        public IActionResult CreateRegion([FromBody] RegionCreateDto createRegion)
        {
            if (createRegion == null)
            {
                return(BadRequest(new TransActionResponse("No Region entered.")));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(new TransActionResponse(ModelState)));
            }
            if (_unitOfWork.Region.RegionExists(createRegion.Name))
            {
                return(BadRequest(new TransActionResponse("Region Already Exists")));
            }

            var newRegion = _mapper.Map <TraRegion>(createRegion);

            _unitOfWork.Region.Create(newRegion);


            if (!_unitOfWork.Save())
            {
                return(StatusCode(500, new TransActionResponse("A problem happened while handling your request.")));
            }

            var createRegionResult = _mapper.Map <RegionDto>(newRegion);

            return(CreatedAtRoute("GetRegion", new { id = createRegionResult.RegionId }, new TransActionResponse(createRegionResult)));
        }
Exemplo n.º 3
0
        public async Task Should_Create()
        {
            // Arrange
            var createDto = new RegionCreateDto
            {
                Name = "Hawaii"
            };

            var expectedDto = new RegionDto
            {
                Name       = createDto.Name,
                CreatedBy  = _staff.DisplayName,
                CreatedAt  = FakeDateTime.UtcNow,
                ModifiedAt = null,
                ModifiedBy = null,
            };

            // Act
            HttpResponseMessage responseMessage = await _authenticatedServer
                                                  .CreateClient()
                                                  .AuthenticateWith(_staff)
                                                  .PostAsync(ApiEndpoints.RegionsController.Post(), BuildStringContent(createDto));

            // Assert
            responseMessage.StatusCode.Should().Be(HttpStatusCode.Created);
            RegionDto result = await DeserializeResponseMessageAsync <RegionDto>(responseMessage);

            result.Should().BeEquivalentTo(expectedDto, opt => opt
                                           .Excluding(dto => dto.Id));
            result.Id.Should().NotBeEmpty();
            responseMessage.Headers.Location.AbsolutePath.Should().Be($"/{ApiEndpoints.RegionsController.Get(result.Id)}");
        }
Exemplo n.º 4
0
        public ActionResult <RegionReadDto> CreateRegion(RegionCreateDto regionCreateDto)
        {
            var receievedata = _mapper.Map <Region>(regionCreateDto);

            _repo.CreateRegion(receievedata);
            _repo.SaveChanges();
            var newdata = _mapper.Map <RegionReadDto>(receievedata);

            return(CreatedAtRoute(nameof(GetRegionById), new { Id = newdata.RegionId }, newdata));
        }
Exemplo n.º 5
0
        public void Should_Map()
        {
            // Arrange
            var regionDto = new RegionCreateDto {
                Name = "Name"
            };
            var expectedCommand = new Create.Command {
                Name = regionDto.Name
            };

            // Act
            Create.Command command = _mapper.Map <Create.Command>(regionDto);

            // Assert
            command.Should().BeEquivalentTo(expectedCommand);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <RegionDto> > Post([FromBody] RegionCreateDto createDto)
        {
            RegionDto createdDto = await _regionService.CreateAsync(createDto);

            return(CreatedAtAction(nameof(GetById), new { id = createdDto.Id }, createdDto));
        }