public async Task <MessageAndStatusAndData <int> > Handle(DeleteListCommand request, CancellationToken cancellationToken)
        {
            if (!CheckIntegrityList(request.ItemId, request.ListAggregationId))
            {
                return(MessageAndStatusAndData.Fail <int>("Forbbidden"));
            }


            _context.Lists.Remove(_context.Lists.Single(a => a.ListId == request.ItemId));
            var amount = await _context.SaveChangesAsync();


            return(await Task.FromResult(MessageAndStatusAndData.Ok(amount, "OK")));
        }
Exemplo n.º 2
0
        public async Task <MessageAndStatusAndData <List> > Handle(EditListCommand request, CancellationToken cancellationToken)
        {
            var listItemEntity = _mapper.Map <ListEntity>(request.List);


            if (!CheckIntegrityList(request.List.ListId, request.ListAggregationId))
            {
                return(MessageAndStatusAndData.Fail <List>("Forbbidden"));
            }

            //_context.ListItems.Remove(_context.ListItems.Single(a => a.ListItemId == ItemId));

            _context.Entry <ListEntity>(listItemEntity).Property(nameof(ListEntity.ListName)).IsModified = true;
            var amount = await _context.SaveChangesAsync();

            var listItem = _mapper.Map <List>(listItemEntity);

            return(await Task.FromResult(MessageAndStatusAndData.Ok(listItem, "OK")));
        }
Exemplo n.º 3
0
        public async Task <MessageAndStatusAndData <List> > Handle(AddListCommand request, CancellationToken cancellationToken)
        {
            if (!CheckIntegrityListAggr(request.ParentId, request.ListAggregationId))
            {
                return(await Task.FromResult(MessageAndStatusAndData.Fail <List>("Forbbidden.")));
            }


            var listItemEntity = _mapper.Map <EFDataBase.ListEntity>(request.Item);

            listItemEntity.ListAggregatorId = request.ParentId;

            _context.Lists.Add(listItemEntity);
            await _context.SaveChangesAsync();

            request.Item.ListId = listItemEntity.ListId;


            return(await Task.FromResult(MessageAndStatusAndData.Ok <List>(request.Item, "OK")));
        }
        public async Task <MessageAndStatusAndData <ListItem> > Handle(SavePropertyCommand request, CancellationToken cancellationToken)
        {
            if (!CheckIntegrityListItem(request.Item.ListItemId, request.ListAggregationId))
            {
                return(await Task.FromResult(MessageAndStatusAndData.Fail <ListItem>("Forbbidden")));
            }


            var listItemEntity = _mapper.Map <ListItemEntity>(request.Item);


            _context.Entry <ListItemEntity>(listItemEntity).Property(request.PropertyName).IsModified = true;
            var amount = await _context.SaveChangesAsync();

            var listItem = _mapper.Map <ListItem>(listItemEntity);



            return(await Task.FromResult(MessageAndStatusAndData.Ok(listItem, "OK")));
        }
Exemplo n.º 5
0
        public async Task <MessageAndStatusAndData <IEnumerable <int> > > Handle(GetUserIdFromListAggrIdCommand request, CancellationToken cancellationToken)
        {
            var userList = await _context.UserListAggregators.Where(a => a.ListAggregatorId == request.ListAggrId).Select(a => a.UserId).ToListAsync();

            return(MessageAndStatusAndData.Ok(userList.AsEnumerable(), "Ok"));
        }