예제 #1
0
        public async Task <Models.Identification> UpdateAsync(Guid parentId, Models.Identification entity)
        {
            var builder = Builders <Models.Contact> .Filter;
            var filter  = builder.Eq(x => x.Id, parentId)
                          & builder.ElemMatch(x => x.Identifications, it => it.Id == entity.Id);
            var update = Builders <Models.Contact> .Update
                         .Set(x => x.Identifications[-1], entity);

            var result = await _context.Contacts.UpdateOneAsync(filter, update);

            if (result.ModifiedCount != 1)
            {
                throw new ClientFriendlyException($"record update failed {parentId}");
            }
            return(entity);
        }
예제 #2
0
        public async Task <Models.Identification> CreateAsync(Guid parentId, Models.Identification entity)
        {
            entity.Id = Guid.NewGuid();
            var filter = Builders <Models.Contact> .Filter.Eq(x => x.Id, parentId);

            var update = Builders <Models.Contact> .Update
                         .AddToSet(x => x.Identifications, entity);

            var result = await _context.Contacts.UpdateOneAsync(filter, update);

            if (result.ModifiedCount != 1)
            {
                throw new ClientFriendlyException($"record creation failed {parentId}");
            }
            return(entity);
        }