Пример #1
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));
        }
Пример #2
0
 public static model.ListModel Map(this storage.List l)
 {
     return(new model.ListModel()
     {
         Id = l.Id,
         Name = l.Name,
         Items = l.Items.Select(li => new model.ListItem()
         {
             Id = li.Id,
             Question = li.Question,
             Answer = li.Answer,
             ListId = l.Id,
         }).ToList(),
     });
 }