Exemplo n.º 1
0
        public static string Upsert <TEntity>(this MongoCollection <TEntity> collection, Base value) where TEntity : Base
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var currentData = collection.FindById(value.Id);

            if (currentData == null)
            {
                collection.Add(value);
            }
            else
            {
                collection.UpdateById(value);
            }
            return(value.Id);
        }