Ejemplo n.º 1
0
        //get and remove the top item and set the top item to the poinetered item of the removed one
        public async Task <StackItem> Pop()
        {
            var stackItem = await _context.StackItems.FirstOrDefaultAsync(item => item.IsTop == true);

            if (stackItem == null)
            {
                return(null);
            }
            string    newTopId   = null;
            StackItem newTopItem = null;

            if (stackItem.BeforeItemId != null)
            {
                newTopId   = stackItem.BeforeItemId;
                newTopItem = await _context.StackItems.FirstOrDefaultAsync(item => item.Id == newTopId);

                newTopItem.AfterItemId = null;
            }
            else if (stackItem.AfterItemId != null)
            {
                newTopId   = stackItem.AfterItemId;
                newTopItem = await _context.StackItems.FirstOrDefaultAsync(item => item.Id == newTopId);

                newTopItem.BeforeItemId = null;
            }
            if (newTopItem != null)
            {
                newTopItem.IsTop = true;
            }

            _context.StackItems.Remove(stackItem);
            await _context.SaveChangesAsync();

            return(stackItem);
        }
Ejemplo n.º 2
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new DomainException($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }