public async Task <ServiceResponse <Country> > Create(AddCountryRequest request) { try { var checkExist = await _countryRepository.FindOneByConditions(c => c.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); if (checkExist != null) { return(new ServiceResponse <Country>($"A Country with name {request.Name} already exist.")); } var country = new Country { Code = $"CNTRY{_codeGenerator.GenerateRandomString(7)}", Name = request.Name, Description = request.Description }; await _countryRepository.Create(country); return(new ServiceResponse <Country>(country)); } catch (Exception ex) { return(new ServiceResponse <Country>($"An Error Occured While Creating a Country Resource. {ex.Message}")); } }
public async Task <ActionResult> Create(AddCountryViewModel request) { if (!ModelState.IsValid) { Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var addCountryRequest = new AddCountryRequest { Name = request.Name, Description = request.Description }; var result = await _countryService.Create(addCountryRequest); if (!result.Success) { Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Country Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
public async Task <CountryResponse> AddCountryAsync(AddCountryRequest request) { Country country = _countryMapper.Map(request); Country result = _countryRespository.Add(country); int modifiedRecords = await _countryRespository.UnitOfWork.SaveChangesAsync(); _logger.LogInformation(Events.Add, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords); _logger.LogInformation(Events.Add, Messages.ChangesApplied_id, result?.Id); return(_countryMapper.Map(result)); }
public Country AddCountry([FromBody] Country country) { if (country != null) { var business = CountryBusiness.Instance; var request = new AddCountryRequest(this.Context); request.Country = country; country = business.AddCountry(request); } return(country); }
public Country AddCountry(AddCountryRequest request) { Country country = null; if (request != null && request.Country != null) { var dataAccess = new CountryDataAccess(request.Context); country = dataAccess.Add(request.Country); } return(country); }
public Country Map(AddCountryRequest request) { if (request == null) { return(null); } Country country = new Country { Iso3cc = request.Iso3cc, Iso2cc = request.Iso2cc, IsoNumerical = request.IsoNumerical, EconomicArea = request.EconomicArea, Name = request.Name, Type = request.Type, }; return(country); }
public async Task <IActionResult> Post(AddCountryRequest request) { RespContainer <CountryResponse> result = await _mediator.Send(new AddCountryCommand(request)); return(CreatedAtAction(nameof(GetById), new { id = result.Data.Id }, result)); }