private async Task <BuildOn> UpdateBuildOnAsync(string buildOnId, int index, BuildOnManageModel buildOnManageModel) { var update = Builders <BuildOn> .Update .Set(dbBuildOn => dbBuildOn.Index, index) .Set(dbBuildOn => dbBuildOn.Name, buildOnManageModel.Name) .Set(dbBuildOn => dbBuildOn.Description, buildOnManageModel.Description); string fileId = ""; if (buildOnManageModel.Image != null && buildOnManageModel.Image.Length >= 1) { fileId = await _filesService.UploadFile($"buildon_{buildOnId}", buildOnManageModel.Image); update = update.Set(dbBuildOn => dbBuildOn.ImageId, fileId); } await _buildOns.UpdateOneAsync(databaseBuildOn => databaseBuildOn.Id == buildOnId, update ); return(new BuildOn() { Id = buildOnId, ImageId = fileId, Name = buildOnManageModel.Name, Description = buildOnManageModel.Description, }); }
private async Task <BuildOn> CreateBuildOnAsync(int index, BuildOnManageModel buildOnManageModel) { BuildOn buildOn = new BuildOn() { Index = index, Name = buildOnManageModel.Name, Description = buildOnManageModel.Description }; await _buildOns.InsertOneAsync(buildOn); // We directly update the build-on to save the image buildOn = await UpdateBuildOnAsync(buildOn.Id, index, buildOnManageModel); return(buildOn); }