public void Update <M>(List <M> modelsWithNewValues, IUpdateModel updateModel) where M : IModel, new() { var createModel = new MongoDbCreateModel(); var deleteModel = new MongoDbDeleteModel(updateModel.IdentifiersToFilterOn); this.Delete(modelsWithNewValues, deleteModel); this.Create(modelsWithNewValues, createModel); }
public string GetUpdateString(IModel newModel) { // Creating the 'filter' portion of the query by making a dict out of the identifiers that we were // told to filter on, plus the values that the model has for those identifiers. var newModelValuesAndIdentifiers = newModel.GetFieldsWithValues(); var identifiersAndValuesToFilterOn = this.IdentifiersToFilterOn .ToDictionary(key => key, value => newModelValuesAndIdentifiers[value]); var filterPortion = base.GetQueryText(identifiersAndValuesToFilterOn); // In MongoDB, updating == creating since the whole document is replaced anyhow. var mongoDbCreateModel = new MongoDbCreateModel(); var updatePortion = mongoDbCreateModel.GetCreateString(newModel); // Making sure filter for primary key has name _id instead of name of primary key filterPortion = filterPortion.Replace(newModel.GetPrimaryKeyFieldName(), "_id"); return("{" + filterPortion + "," + updatePortion + "}"); }