private async Task <TResponse <bool> > CanUpdate(UpdateInvoiceStatusModel request) { try { var invoiceStatus = await _invoiceStatusCacheService.GetByName(request.Name); if (invoiceStatus != null && invoiceStatus.Id != request.Id) { return(await Fail <bool>(ErrorEnum.INVOICE_STATUS_HAS_EXIST.GetStringValue())); } if (request.IsSendSms && string.IsNullOrEmpty(request.SmsContent)) { return(await Fail <bool>(ErrorEnum.SMS_CONTENT_IS_NOT_NULL_OR_EMPTY.GetStringValue())); } return(await Ok(true)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <ActionResult <bool> > Update(UpdateInvoiceStatusModel request) { return(Ok(await _invoiceStatusService.Update(await GetUserId(), request, GetPermissionId()))); }
public async Task <TResponse <bool> > Update(int userId, UpdateInvoiceStatusModel 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.INVOICE_STATUS_UPDATE, new { request.Id, request.Name, request.Color, request.IsSendSms, request.SmsContent, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result.IsSuccess) { if (result.Data > 0) { #region Update redis cache await _invoiceStatusCacheService.AddOrUpdate(new InvoiceStatusCacheModel { Id = request.Id, Name = request.Name, Color = request.Color, SmsContent = request.SmsContent, IsSendSms = request.IsSendSms }); #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)); } }