public async Task <IActionResult> UpdateFeatureAsync(int id, [FromBody] FeatureResource feature) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Feature domainFeature = await _repository.GetAsync(id); if (domainFeature == null) { return(BadRequest($"Feature with id = {id} does not exist!")); } _mapper.Map(feature, domainFeature); domainFeature.Id = id; await _unitOfWork.CompeleteAsync(); Feature found = await _repository.GetAsync(id); KeyValuePairResource result = _mapper.Map <Feature, KeyValuePairResource>(found); return(Ok(result)); } catch (Exception e) { return(StatusCode(500, e.InnerException?.Message ?? e.Message)); } }
public async Task <IActionResult> CreateFeatureAsync([FromBody] FeatureResource feature) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Feature domainFeature = _mapper.Map <FeatureResource, Feature>(feature); await _repository.CreateAsync(domainFeature); await _unitOfWork.CompeleteAsync(); int id = domainFeature.Id; Feature found = await _repository.GetAsync(id); KeyValuePairResource result = _mapper.Map <Feature, KeyValuePairResource>(found); return(Ok(result)); } catch (Exception e) { return(StatusCode(500, e.InnerException?.Message ?? e.Message)); } }