Beispiel #1
0
        public async Task <bool> DeleteList(string userId, Guid listId)
        {
            var deleteResult = await MongoDbUtil.GetCollection <storage.List>(DBNAME, COLLECTION_LIST)
                               .DeleteOneAsync <storage.List>(l => l.UserId == userId && l.Id == listId);

            return(deleteResult.IsAcknowledged && deleteResult.DeletedCount > 0);
        }
Beispiel #2
0
        public async Task <model.ListModel> GetList(string userId, Guid id)
        {
            var storageList = await Task.FromResult(MongoDbUtil.GetCollection <storage.List>(DBNAME, COLLECTION_LIST).AsQueryable()
                                                    .Where(l => l.UserId == userId)
                                                    .Where(l => l.Id == id)
                                                    .FirstOrDefault()); // SingleOrDefault

            return(storageList?.Map());
        }
Beispiel #3
0
        public async Task <model.ListModel> AddList(string userId, model.ListModel list)
        {
            var insertOptions = new InsertOneOptions
            {
                BypassDocumentValidation = false,
            };

            var storageList = list.Map(userId);
            await MongoDbUtil.GetCollection <List>(DBNAME, COLLECTION_LIST).InsertOneAsync(storageList, insertOptions);

            return(list);
        }
Beispiel #4
0
        public Task <IEnumerable <model.ListSummary> > GetAllLists(string userId)
        {
            var q = MongoDbUtil.GetCollection <storage.List>(DBNAME, COLLECTION_LIST).AsQueryable()
                    .Where(l => l.UserId == userId)
                    .Select(l => new model.ListSummary()
            {
                Id        = l.Id,
                Name      = l.Name,
                ItemCount = l.Items.Count
            });

            return(Task.FromResult(q
                                   .AsEnumerable()));
        }
Beispiel #5
0
        public async Task <storage.List> UpdateStorageList(storage.List list)
        {
            var col = MongoDbUtil.GetCollection <storage.List>(DBNAME, COLLECTION_LIST);

            var builder = Builders <storage.List> .Filter;
            var filters = builder.Eq(sl => sl.Id, list.Id) & builder.Eq(sl => sl.UserId, list.UserId);
            var result  = await col.ReplaceOneAsync(filters, list);

            if (result.ModifiedCount != 1)
            {
                throw new InvalidOperationException("ReplaceOne failed");
            }

            return(col.AsQueryable().First(l => l.Id == list.Id));
        }