public IActionResult Update(DataSourceDTO dataSourceDTO, int Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { IDataResult <DataSource> result = _iDataSourceService.GetById(Id); if (result == null) { return(BadRequest(result.Message)); } else { _iMapper = DataSourceMapping.GetMapper().CreateMapper(); DataSource dataSource = _iMapper.Map <DataSourceDTO, DataSource>(dataSourceDTO); IResult updateResult = _iDataSourceService.Update(dataSource); if (updateResult.Success) { return(Ok(updateResult.Message)); } return(BadRequest(updateResult.Message)); } } }
public async Task <IActionResult> UpdateAsync(DataSourceDTO dataSourceDTO, int Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { IDataResult <DataSource> dataResult = await _iDataSourceService.FindByIdAsync(Id); if (dataResult.Data == null) { return(BadRequest(dataResult.Message)); } _iMapper = DataSourceMapping.GetMapper().CreateMapper(); DataSource dataSource = _iMapper.Map <DataSourceDTO, DataSource>(dataSourceDTO); IResult result = await _iDataSourceService.UpdateAsync(dataSource); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); } }
public IActionResult Add(DataSourceDTO dataSourceDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { _iMapper = DataSourceMapping.GetMapper().CreateMapper(); DataSource dataSource = _iMapper.Map <DataSourceDTO, DataSource>(dataSourceDTO); IResult result = _iDataSourceService.Add(dataSource); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); } }
public async Task <IActionResult> AddAsync(DataSourceDTO dataSourceDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { _iMapper = DataSourceMapping.GetMapper().CreateMapper(); DataSource dataSource = _iMapper.Map <DataSourceDTO, DataSource>(dataSourceDTO); IResult result = await _iDataSourceService.AddAsync(dataSource); if (result.Success) { return(Ok(result.Message)); } return(BadRequest($"{result.Message} \n Try Again later can be either server error or user error ")); } }