public async Task <IActionResult> Post([FromBody] InsertRegionState model) { var result = await regionServices.Add(model); if (result.Status) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <TypedResult <StateDTO> > Add(InsertRegionState regionState) { try { ICollection <RegionState> existsRecords = await regionStateRepo .GetList(condition : x => x.RegionCountryId == regionState.CountryId && x.Title.Equals(regionState.Title)); if (existsRecords.Any()) { throw new InvalidOperationException(ErrorMessages.THIS_RECORD_ALREADY_EXISTS); } RegionState entity = _mapper.Map <RegionState>(regionState); RegionState result = await regionStateRepo.Add(entity); return(new TypedResult <StateDTO>(_mapper.Map <StateDTO>(result))); } catch (Exception ex) { return(new TypedResult <StateDTO>(ex)); } }