Exemple #1
0
        public async Task <GetOneResult <TEntity> > GetOne(FilterDefinition <TEntity> filter)
        {
            var res = new GetOneResult <TEntity>();

            try
            {
                var collection = GetCollection();
                var entity     = await collection.Find(filter).SingleOrDefaultAsync();

                if (entity != null)
                {
                    res.Entity = entity;
                }

                res.Success = true;
                return(res);
            }
            catch (Exception ex)
            {
                res.Message = ExceptionHelper.NotifyException("GetOne",
                                                              string.Concat("Exception getting one ", typeof(TEntity).Name),
                                                              ex);
                return(res);
            }
        }
Exemple #2
0
        public async Task <GetOneResult <TEntity> > GetAndUpdateOne(FilterDefinition <TEntity> filter,
                                                                    UpdateDefinition <TEntity> update, FindOneAndUpdateOptions <TEntity, TEntity> options)
        {
            var result = new GetOneResult <TEntity>();

            try
            {
                var collection = GetCollection();
                result.Entity = await collection.FindOneAndUpdateAsync(filter, update, options);

                result.Success = true;
                result.Message = "OK";
                return(result);
            }
            catch (Exception ex)
            {
                result.Message = ExceptionHelper.NotifyException("GetAndUpdateOne",
                                                                 string.Concat("Exception getting and updating entity: ", typeof(TEntity).Name), ex);
                return(result);
            }
        }