예제 #1
0
        private async Task <BuildOnStep> UpdateBuildOnStepAsync(string buildOnId, string buildonStepId, int index, BuildOnStepManageModel buildOnStepManageModel)
        {
            var update = Builders <BuildOnStep> .Update
                         .Set(dbBuildOnStep => dbBuildOnStep.Index, index)
                         .Set(dbBuildOnStep => dbBuildOnStep.Name, buildOnStepManageModel.Name)
                         .Set(dbBuildOnStep => dbBuildOnStep.Description, buildOnStepManageModel.Description)
                         .Set(dbBuildOnStep => dbBuildOnStep.ReturningType, buildOnStepManageModel.ReturningType)
                         .Set(dbBuildOnStep => dbBuildOnStep.ReturningDescription, buildOnStepManageModel.ReturningDescription)
                         .Set(dbBuildOnStep => dbBuildOnStep.ReturningLink, buildOnStepManageModel.ReturningLink);

            string fileId = "";

            if (buildOnStepManageModel.Image != null && buildOnStepManageModel.Image.Length >= 1)
            {
                fileId = await _filesService.UploadFile($"buildonstep_{buildonStepId}", buildOnStepManageModel.Image);

                update = update.Set(dbBuildOnStep => dbBuildOnStep.ImageId, fileId);
            }

            await _buildOnSteps.UpdateOneAsync(databaseBuildOnStep =>
                                               databaseBuildOnStep.Id == buildonStepId,
                                               update
                                               );

            return(new BuildOnStep()
            {
                Id = buildonStepId,
                BuildOnId = buildOnId,
                ImageId = fileId,

                Name = buildOnStepManageModel.Name,
                Description = buildOnStepManageModel.Description,
                ReturningType = buildOnStepManageModel.ReturningType,
                ReturningDescription = buildOnStepManageModel.ReturningDescription,
                ReturningLink = buildOnStepManageModel.ReturningLink
            });
        }
예제 #2
0
        private async Task <BuildOnStep> CreateBuildOnStepAsync(string buildOnId, int index, BuildOnStepManageModel buildOnStepManageModel)
        {
            BuildOnStep buildOnStep = new BuildOnStep()
            {
                BuildOnId = buildOnId,
                Index     = index,

                Name                 = buildOnStepManageModel.Name,
                Description          = buildOnStepManageModel.Description,
                ReturningType        = buildOnStepManageModel.ReturningType,
                ReturningDescription = buildOnStepManageModel.ReturningDescription,
                ReturningLink        = buildOnStepManageModel.ReturningLink
            };

            await _buildOnSteps.InsertOneAsync(buildOnStep);

            // We directly update the build-on step to save the image
            buildOnStep = await UpdateBuildOnStepAsync(buildOnId, buildOnStep.Id, index, buildOnStepManageModel);

            return(buildOnStep);
        }