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