public async Task <IActionResult> Create(Country country) { if (ModelState.IsValid) { try { await _countryRepository.CreateAsync(country); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There are a record with the same name."); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(country)); }
public async Task <IActionResult> CreateCountry(Country country) { if (ModelState.IsValid) { country.CreationDate = DateTime.UtcNow; country.IsActive = true; try { await _countryRepository.CreateAsync(country); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, $"There is allready a country registered with the name {country.CountryName} please insert another"); return(View(country)); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); return(View(country)); } } } return(View(country)); }
public async Task <IActionResult> Create(Country country) { if (ModelState.IsValid) { try { await _countryRepository.CreateAsync(country); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "Already there is a country with that name"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(country)); }
public async Task <IActionResult> Create(Country country) { if (ModelState.IsValid) { await _countryRepository.CreateAsync(country); return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <IActionResult> Handle(CreateCountryRequest request, CancellationToken cancellationToken) { var validationResult = await _countryValidator.ValidateAsync(request.Country, cancellationToken); if (!validationResult.IsValid) { return(new BadRequestObjectResult(validationResult.Errors)); } var country = _mapper.Map <Country>(request.Country); country = await _countryRepository.CreateAsync(country); return(new CreatedAtRouteResult(country.Id, _mapper.Map <CountryDTO>(country))); }
public async Task <IActionResult> Create([FromBody] Country country) { if (country == null) { return(BadRequest()); } if (country.Name == null) { return(BadRequest()); } Country added = await countryRepository.CreateAsync(country); return(CreatedAtRoute("GetCountry", new { id = added.Id }, country)); }
public async Task <IActionResult> Post([FromBody] Country item) { if (item == null) { return(StatusCode(422, "Відсутні данні.")); } if (string.IsNullOrEmpty(item.Name)) { return(StatusCode(422, "Відсутня назва.")); } var result = await _countryRepository.CreateAsync(item); if (result.Result == OperationResult.Ok) { return(StatusCode(201, result.Value)); } return(StatusCode(422, result.Message)); }
public async Task <IActionResult> Post(Country country) { await _countryRepository.CreateAsync(country); return(NoContent()); }
public async Task <int> CreateAsync(CountryModifyRequest request) { return(await _countryRepository.CreateAsync(request)); }