public Task AddMembershipAsync(string userId, UserMembershipEntity membership) { return(Task.Run(() => { IMongoQuery query = Query <UserEntity> .EQ(entity => entity.Id, userId); UpdateBuilder <UserEntity> update = Update <UserEntity> .AddToSet(entity => entity.Memberships, membership); Collection.Update(query, update); })); }
public Task UpdateMembershipAsync(string userId, UserMembershipEntity membership) { return(Task.Run(() => { IMongoQuery query = Query.And( Query <UserEntity> .EQ(e => e.Id, userId), Query <UserEntity> .ElemMatch(e => e.Memberships, builder => builder.EQ(m => m.IdentityProvider, membership.IdentityProvider)), Query <UserEntity> .ElemMatch(e => e.Memberships, builder => builder.EQ(m => m.UserIdentifier, membership.UserIdentifier))); string membershipsCollectionName = NameOfHelper.PropertyName <UserEntity>(x => x.Memberships); UpdateBuilder update = Update.Set(string.Format("{0}.$", membershipsCollectionName), BsonDocumentWrapper.Create(membership)); Collection.Update(query, update); })); }
public async Task <HttpResponseMessage> Post(TwitterStatusModel model) { // If token and token secret was not overridden use last one saved if (string.IsNullOrEmpty(model.Token) || string.IsNullOrEmpty(model.TokenSecret)) { UserMembershipEntity twitterMembership = Memberships.FirstOrDefault(p => p.IdentityProvider == ProviderType.Twitter.ToString()); if (twitterMembership != null) { model.Token = twitterMembership.Token; model.TokenSecret = twitterMembership.TokenSecret; } } await _twitterServiceService.SetStatusAsync(model); return(Request.CreateResponse(HttpStatusCode.OK)); }