public async Task <IActionResult> Post(string queueItemId, [FromBody] string[] requests) { try { var entityId = new Guid(queueItemId); var queueItem = queueItemRepository.Find(0, 1).Items?.Where(q => q.Id.ToString() == queueItemId).FirstOrDefault(); long?payload = 0; if (requests.Length == 0 || requests == null) { ModelState.AddModelError("Attach", "No files uploaded to attach"); return(BadRequest(ModelState)); } foreach (var request in requests) { var binaryObject = binaryObjectRepository.Find(null, q => q.Id == Guid.Parse(request))?.Items?.FirstOrDefault(); if (binaryObject == null) { ModelState.AddModelError("Save", "No file attached"); return(BadRequest(ModelState)); } long?size = binaryObject.SizeInBytes; if (size <= 0) { ModelState.AddModelError("File attachment", $"File size of file {binaryObject.Name} cannot be 0"); return(BadRequest(ModelState)); } //create queue item attachment QueueItemAttachment queueItemAttachment = new QueueItemAttachment() { BinaryObjectId = (Guid)binaryObject.Id, QueueItemId = Guid.Parse(queueItemId), CreatedBy = applicationUser?.UserName, CreatedOn = DateTime.UtcNow, SizeInBytes = (long)binaryObject.SizeInBytes }; repository.Add(queueItemAttachment); payload += queueItemAttachment.SizeInBytes; } //update queue item payload queueItem.PayloadSizeInBytes += (long)payload; queueItemRepository.Update(queueItem); await webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItem.Id.ToString(), queueItem.Name).ConfigureAwait(false); var queueItemAttachments = repository.Find(null).Items?.Where(q => q.QueueItemId == entityId); return(Ok(queueItemAttachments)); } catch (Exception ex) { ModelState.AddModelError("Attach", ex.Message); return(BadRequest(ModelState)); } }
public QueueItem FindQueueItem(string state, string queueId) { var item = _repo.Find(0, 1).Items .Where(q => q.QueueId.ToString() == queueId) .Where(q => q.State == state) .Where(q => !q.IsLocked) .Where(q => q.IsDeleted == false) .Where(q => q.PostponeUntilUTC <= DateTime.UtcNow || q.PostponeUntilUTC == null) .OrderByDescending(q => q.Priority) .ThenBy(q => q.CreatedOn) .FirstOrDefault(); return(item); }
public bool CheckReferentialIntegrity(string id) { Guid queueId = new Guid(id); var lockedQueueItems = queueItemRepo.Find(0, 1).Items? .Where(q => q.QueueId == queueId && q.IsLocked); return(lockedQueueItems.Count() > 0); }
public async Task <IActionResult> DeleteAttachment(string id, string driveName = null) { try { var attachment = repository.GetOne(Guid.Parse(id)); var queueItem = _queueItemRepository.Find(null).Items?.Where(q => q.Id == attachment.QueueItemId).FirstOrDefault(); _manager.DeleteOne(attachment, queueItem, driveName); await base.DeleteEntity(id); await _webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItem.Id.ToString(), queueItem.Name).ConfigureAwait(false); return(Ok()); } catch (Exception ex) { return(ex.GetActionResult()); } }
public Queue CheckReferentialIntegrity(string id) { Guid entityId = new Guid(id); var existingQueue = _queueRepo.GetOne(entityId); if (existingQueue == null) { throw new EntityDoesNotExistException("Queue could not be found"); } var lockedQueueItems = _queueItemRepo.Find(0, 1).Items? .Where(q => q.QueueId == entityId && q.IsLocked); bool lockedChildExists = lockedQueueItems.Count() > 0; if (lockedChildExists) { throw new EntityOperationException("Referential integrity in queue items table; please remove any locked items associated with this queue first"); } return(existingQueue); }