Esempio n. 1
0
        public async Task AddUserNewCarAsync(CarEntity carEntity)
        {
            if (carEntity.IsCurrent)
            {
                var builder = Builders <CarEntity> .Filter;

                await CarEntities.UpdateManyAsync(builder.Eq("UserId", carEntity.UserId), new BsonDocument("$set", new BsonDocument("IsCurrent", false)));
            }

            if (!await CarEntities.Find(x => x.UserId == carEntity.UserId).AnyAsync())
            {
                carEntity.IsCurrent = true;
            }


            await CarEntities.InsertOneAsync(carEntity);
        }
Esempio n. 2
0
        public async Task <bool> SetUserCurCarAsync(string carEntityId, string userId)
        {
            if (carEntityId != null && userId != null)
            {
                var builder = Builders <CarEntity> .Filter;
                var filter  = builder.Eq("UserId", userId) & builder.Eq("Id", carEntityId);

                await CarEntities.UpdateManyAsync(builder.Eq("UserId", userId), new BsonDocument("$set", new BsonDocument("IsCurrent", false)));

                var result = await CarEntities.UpdateOneAsync(
                    filter,
                    new BsonDocument("$set", new BsonDocument("IsCurrent", true)));

                if (result.ModifiedCount > 0)
                {
                    return(true);
                }
            }
            return(false);
        }