private async Task <TResponse <bool> > CanInsert(InsertCandidateStatusModel request) { try { var candidateStatus = await _candidateStatusCacheService.GetByName(request.Name); if (candidateStatus != null) { return(await Fail <bool>(ErrorEnum.CANDIDATE_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> > Add(InsertCandidateStatusModel request) { return(Ok(await _candidateStatusService.Add(await GetUserId(), request, GetPermissionId()))); }
public async Task <TResponse <bool> > Add(int userId, InsertCandidateStatusModel request, int permissionId) { try { var checkValid = await _userService.CheckPermission(userId, permissionId); if (checkValid.IsSuccess) { var canInsert = await CanInsert(request); if (canInsert.IsSuccess) { var result = await WriteRepository.ExecuteScalarAsync <int>(SqlQuery.CANDIDATE_STATUS_INSERT, new { request.Name, request.Color, request.SortOrder, request.IsSendSms, request.SmsContent, UserCreated = userId, DateCreated = DateTime.Now, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result.IsSuccess) { if (result.Data > 0) { #region Update redis cache await _candidateStatusCacheService.AddOrUpdate(new CandidateStatusCacheModel { Id = result.Data, Name = request.Name, Color = request.Color, SortOrder = request.SortOrder, 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>(canInsert.Message)); } return(await Fail <bool>(checkValid.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }