public CCCommandProcessingDetailViewModel GetCommandProcessingDetails(Guid costCentreId, Guid applicationId,
     int currentPageIndex, int pageSize, CommandProcessingStatus status, out int count)
 {
     var costCentre = _costCentreRepository.GetById(costCentreId);
     var items = _commandProcessingAuditRepository.GetByApplicationId(applicationId, currentPageIndex, pageSize, status, out count);
     var vm = new CCCommandProcessingDetailViewModel(costCentre, items);
     vm.Items = vm.Items.ToList();
     return vm;
 }
 public void SetCommandStatus(Guid commandId, CommandProcessingStatus status)
 {
     CommandProcessingAudit command = GetByCommandId(commandId);
     if(command!=null)
     {
         command.Status = status;
         _commandProcessingAuditCollection.Save(command);
     }
 }
 public List<CommandProcessingAudit> GetAllByStatus(CommandProcessingStatus status)
 {
     DateTime date = DateTime.Now.AddDays(-5);
     foreach (var cmd in _commandProcessingAuditCollection.AsQueryable().Where(s=>s.DateInserted< date && s.Status==CommandProcessingStatus.MarkedForRetry))
     {
         cmd.Status = CommandProcessingStatus.ManualProcessing;
         _commandProcessingAuditCollection.Save(cmd);
     }
     return _commandProcessingAuditCollection.AsQueryable().OrderBy(s=>s.CostCentreCommandSequence).ThenBy(s=>s.CostCentreApplicationId).Where(s=>s.Status==status).ToList();
 }
 public List<CommandProcessingAudit> GetByApplicationId(Guid costCentreApplicationId, int index, int size, CommandProcessingStatus status, out int count)
 {
     throw new NotImplementedException();
 }
 public List<CommandProcessingAudit> GetAllByStatus(CommandProcessingStatus status)
 {
     throw new NotImplementedException();
 }
 private TableResult AddCommandStatusIndex(Guid commandId, CommandProcessingStatus status, string ccid)
 {
     var statusIndex = new CommandProcessingAuditStatusIndexTable
         {
             PartitionKey = status.ToString(),
             RowKey = commandId.ToString(),
             CostCentreId = new Guid(ccid)
         };
     TableOperation to3 = TableOperation.Insert(statusIndex);
     TableResult r3 = _commandStatus.Execute(to3);
     return r3;
 }
        public void SetCommandStatus(Guid commandId, CommandProcessingStatus status)
        {
            _logger.InfoFormat("#### ---> Command {0} SetCommandStatus {1} ", commandId.ToString(), status.ToString());

            string existingStatus = null;
            //update command
            TableResult commandAudit = CommandAuditTableLookup(commandId);
            if (commandAudit == null)
                return;

            CommandProcessingAuditTable command = (CommandProcessingAuditTable)commandAudit.Result;
            existingStatus = ((CommandProcessingStatus)command.Status).ToString();

            var tasks = new List<Task<TableResult>>();

            tasks.Add(Task.Run(() =>
                {
                    command.Status = (int)status;
                    TableOperation updateOperation = TableOperation.Replace(command);
                    return _commandTable.Execute(updateOperation);
                }));


            //add to command status
            if (status == CommandProcessingStatus.Complete) //should not need to index complete??
                return;
            tasks.Add(Task.Run(() =>
                {
                    //remove existing
                    var csFC = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal,commandId.ToString());
                    var csQry = new TableQuery<CommandProcessingAuditStatusIndexTable>().Where(csFC);
                    var csResults = _commandStatus.ExecuteQuery(csQry);
                    foreach (var csResult in csResults)
                    {
                        TableOperation deleteOperation = TableOperation.Delete(csResult);
                        _commandStatus.Execute(deleteOperation);
                    }
                    //add new
                    string ccid = command.PartitionKey;
                    return AddCommandStatusIndex(commandId, status, ccid);
                }));

            Task.WaitAll(tasks.ToArray());
        }
 public List<CommandProcessingAudit> GetByApplicationId(Guid costCentreApplicationId, int pageIndex, int pageSize, CommandProcessingStatus status, out int count)
 {
     IQueryable<CommandProcessingAudit> collection;
     if ((int)status == 0)
     {
         collection = _commandProcessingAuditCollection
             .AsQueryable()
             .Where(n => n.CostCentreApplicationId == costCentreApplicationId);
         count = collection.Count();
     }
     else
     {
         collection = _commandProcessingAuditCollection
             .AsQueryable()
             .Where(n => n.CostCentreApplicationId == costCentreApplicationId && n.Status == status);
         count = collection.Count();
     }
     return collection.OrderByDescending(n => n.DateInserted)
         .Skip(pageIndex * pageSize).Take(pageSize)
         .ToList(); 
 }