public async Task <DomainModels.Profile> CreateAsync(DomainModels.Profile entity) { entity.Subscriptions = new List <DomainModels.Subscription>(); await collection.InsertOneAsync(entity); return(entity); }
public async Task <DomainModels.Profile> UpdateAsync(DomainModels.Profile entity) { var filter = Builders <DomainModels.Profile> .Filter.Eq(p => p.Id, entity.Id); var update = Builders <DomainModels.Profile> .Update.Set(p => p.DisplayName, entity.DisplayName) .Set(p => p.Type, entity.Type); var result = await collection.UpdateOneAsync(filter, update); if (!result.IsAcknowledged) { throw new InternalException($"Failed to update profile {entity.Id}"); } if (result.MatchedCount == 0) { throw new BadRequestException("Profile is not available in database"); } if (result.ModifiedCount == 0) { throw new InternalException($"Failed to update profile {entity.Id}"); } return(entity); }