public async Task <SenderDetailResponse> GetSenderAsync(SenderDetailRequest request) { await ValidateRequestAsync(request); var entity = _senderRepository.FindOne(x => x.Id == request.Id); if (entity == null) { throw new EntityNotFoundException(); } return(_mapper.Map <SenderDetailResponse>(entity)); }
public async Task <HookCreateResponse> CreateHookAsync(HookCreateRequest request) { await ValidateRequestAsync(request); var sender = _senderRepository.FindOne(x => x.Token == request.SenderToken); if (request.EventId.HasValue) { var entity = _hookRepository.Insert(new HookEntity() { EventId = request.EventId.Value, SenderId = sender.Id, Data = request.Data, StatusId = (int)StatusEnum.Created, Message = StatusEnum.Created.ToString() }); _requesterQueue.Add(entity.Id); return(new HookCreateResponse() { Status = true, Message = "Created 1 hook(s)" }); } else if (request.ActionId.HasValue) { var events = _eventRepository.FindMany(x => x.ActionId == request.ActionId.Value && (x.SenderId == null || x.SenderId == sender.Id)); foreach (var item in events) { var entity = _hookRepository.Insert(new HookEntity() { EventId = item.Id, SenderId = sender.Id, Data = request.Data, StatusId = (int)StatusEnum.Created, Message = StatusEnum.Created.ToString() }); _requesterQueue.Add(entity.Id); } return(new HookCreateResponse() { Status = true, Message = $"Created {events.Count()} hook(s)" }); } else if (!string.IsNullOrEmpty(request.ActionName)) { var events = _eventRepository.FindMany(x => x.Action.Name == request.ActionName && (x.SenderId == null || x.SenderId == sender.Id)); foreach (var item in events) { var entity = _hookRepository.Insert(new HookEntity() { EventId = item.Id, SenderId = sender.Id, Data = request.Data, StatusId = (int)StatusEnum.Created, Message = StatusEnum.Created.ToString() }); _requesterQueue.Add(entity.Id); } return(new HookCreateResponse() { Status = true, Message = $"Created {events.Count()} hook(s)" }); } else { throw new InvalidOperationException(); } }