public IActionResult Load([FromBody] DbExtractProtocolDTO entity) { if (null == entity) { return(BadRequest()); } if (!entity.IsValid()) { return(BadRequest()); } try { //check if busy var extractHistory = _psmartExtractService.HasStarted(entity.Extract.Id); if (extractHistory.IsStarted()) { var eventHistory = _psmartExtractService.GetStatus(entity.Extract.Id); if (null != eventHistory) { return(Ok(new { IsComplete = false, IsStarted = true, eEvent = eventHistory })); } } _psmartExtractService.Clear(); _psmartExtractService.Find(entity); _psmartExtractService.Sync(entity); _psmartExtractService.Complete(entity.Extract.Id); var history = _psmartExtractService.GetStatus(entity.Extract.Id); if (null != history) { return(Ok(new { IsComplete = true, IsStarted = false, eEvent = history })); } throw new ArgumentException("Server could not precess your"); } catch (Exception e) { var msg = $"Error parsing {nameof(Extract)} {_psmartExtractService.GetLoadError()}"; Log.Error(msg); Log.Error($"{e}"); return(StatusCode(500, msg)); } }
public async Task <IActionResult> Send([FromBody] SendPackageDTO packageDTO) { if (!packageDTO.IsValid()) { return(BadRequest()); } try { if (packageDTO.Docket.IsSameAs("PSMART")) { //check if sending var extractHistory = _psmartExtractService.HasStarted(packageDTO.ExtractId.Value, ExtractStatus.Sending, ExtractStatus.Sent); if (null != extractHistory && extractHistory.IsSending()) { //prevent sending var eventHistory = _psmartExtractService.GetStatus(packageDTO.ExtractId.Value); if (null != eventHistory) { return(Ok(new { IsComplete = false, IsSending = true, eEvent = eventHistory })); } } var psmartdata = _psmartStageRepository.GetAll().ToList(); if (psmartdata.Count > 0) { var psmartDTO = psmartdata.Select(x => new SmartMessage { Eid = x.EId, Id = x.Uuid, PayLoad = x.Shr }).ToList() .ToList(); var bag = new SmartMessageBag(psmartDTO); _extractHistoryRepository.UpdateStatus(packageDTO.ExtractId.Value, ExtractStatus.Sending); var response = await _psmartSendService.SendAsync(packageDTO, bag); if (null != response) { if (response.IsValid()) { // update sent _extractHistoryRepository.UpdateStatus(packageDTO.ExtractId.Value, ExtractStatus.Sent, bag.Message.Count); _psmartExtractService.Complete(packageDTO.ExtractId.Value); _psmartStageRepository.UpdateStatus(bag.Message.Select(x => x.Eid), response.IsValid(), response.RequestId); var history = _psmartExtractService.GetStatus(packageDTO.ExtractId.Value); if (null != history) { return(Ok(new { IsComplete = true, IsSending = false, eEvent = history })); } return(Ok(response)); } } } } return(BadRequest()); } catch (Exception e) { var msg = $"Error loading {nameof(Extract)}(s)"; Log.Error(msg); Log.Error($"{e}"); return(StatusCode(500, msg)); } }