public async Task <TResponse <bool> > Update(int userId, UpdatePayMethodModel request, int permissionId) { try { var checkValid = await _userService.CheckPermission(userId, permissionId); if (checkValid.IsSuccess) { var canUpdate = await CanUpdate(request); if (canUpdate.IsSuccess) { var result = await WriteRepository.ExecuteAsync(SqlQuery.PAY_METHOD_UPDATE, new { request.Id, request.Name, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result.IsSuccess) { if (result.Data > 0) { #region Update redis cache await _payMethodCacheService.AddOrUpdate(new PayMethodCacheModel { Id = request.Id, Name = request.Name }); #endregion return(await Ok(true)); } return(await Fail <bool>(ErrorEnum.BAD_REQUEST.GetStringValue())); } return(await Fail <bool>(result.Message)); } return(await Fail <bool>(canUpdate.Message)); } return(await Fail <bool>(checkValid.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
private async Task <TResponse <bool> > CanUpdate(UpdatePayMethodModel request) { try { var payMethod = await _payMethodCacheService.GetByName(request.Name); if (payMethod != null && payMethod.Id != request.Id) { return(await Fail <bool>(ErrorEnum.PAY_METHOD_HAS_EXIST.GetStringValue())); } return(await Ok(true)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <ActionResult <bool> > Update(UpdatePayMethodModel request) { return(Ok(await _payMethodService.Update(await GetUserId(), request, GetPermissionId()))); }