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