[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); }
public async Task <ActionResult> AddAsync(CountryDto countryDto) { CountryModel country = _mapper.Map <CountryModel>(countryDto); await _countryService.AddAsync(country); return(Ok()); }
//[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)); }
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); } }
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); } }
public async Task <IActionResult> Save(CountryDto countryDto) { var countrySave = await _countryService.AddAsync(_mapper.Map <Country>(countryDto)); return(Created(string.Empty, _mapper.Map <CountryDto>(countrySave))); }
public async Task <IActionResult> Post([FromBody] Country value) { await _countryService.AddAsync(value); return(Ok()); }