Exemplo n.º 1
0
        [TestMethod] public async Task AddingDuplicateCountryReturnsDuplicateResult()
        {
            // Arrange
            Country countryToAdd = new Country()
            {
                Name = "Belarus"
            };

            // Act
            AddResult addResult = await _countryService.AddAsync(countryToAdd);

            // Assert
            Assert.AreEqual(ResultTypes.Duplicate, addResult.ResultType);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddAsync(CountryDto countryDto)
        {
            CountryModel country = _mapper.Map <CountryModel>(countryDto);

            await _countryService.AddAsync(country);

            return(Ok());
        }
Exemplo n.º 3
0
        //[Authorize]
        public override async Task <CountryReply> Create(CountryCreateRequest request, ServerCallContext context)
        {
            //var currentUser = context.GetHttpContext().User;
            //throw new RpcException(new Status(StatusCode.InvalidArgument,"test"), "test");
            var createCountry = _mapper.Map <Country>(request);
            var country       = await _countryService.AddAsync(createCountry);

            return(_mapper.Map <CountryReply>(country));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> AddAsync([FromBody] Country country)
        {
            BlCountry countryBl = _mapper.Map <BlCountry>(country);

            AddResult addAddResult = await _countryService.AddAsync(countryBl);

            if (addAddResult.ResultType == ResultTypes.Duplicate)
            {
                return(BadRequest());
            }

            return(Ok(new { Id = addAddResult.ItemId }));
        }
        public override async Task <CountryReply> Create(CountryCreateRequest request, ServerCallContext context)
        {
            var currentUser = context.GetHttpContext().User;

            try
            {
                var createCountry = _mapper.Map <Country>(request);
                var country       = await _countryService.AddAsync(createCountry);

                return(_mapper.Map <CountryReply>(country));
            }
            catch (Exception e)
            {
                throw new RpcException(Status.DefaultCancelled, e.Message);
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Add(AddCountryViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.Name) && await countryService.ExistsAsync(model.Name))
            {
                ModelState.AddModelError(nameof(model.Name), CountryWithNameExistsMessage);
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await countryService.AddAsync(model.Name);

            return(RedirectToAction(nameof(Add)));
        }
        public override async Task <CountryReply> Create(CountryCreateRequest request, ServerCallContext context)
        {
            var currentUser = context.GetHttpContext().User;

            try
            {
                var createCountry = _mapper.Map <Country>(request);
                var country       = await _countryService.AddAsync(createCountry);

                return(_mapper.Map <CountryReply>(country));
            }
            catch (Exception e)
            {
                var httpContext = context.GetHttpContext();
                httpContext.Response.StatusCode = 500; // Required to fire Polly retry policy, else 200 will be returned
                throw new RpcException(Status.DefaultCancelled, e.Message);
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Save(CountryDto countryDto)
        {
            var countrySave = await _countryService.AddAsync(_mapper.Map <Country>(countryDto));

            return(Created(string.Empty, _mapper.Map <CountryDto>(countrySave)));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Post([FromBody] Country value)
        {
            await _countryService.AddAsync(value);

            return(Ok());
        }