|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
using MongoDB.Driver.Core.Servers; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 问卷调查 (服务) |
|
|
|
@ -83,13 +85,57 @@ public class Ghre_SurveyServices : BaseServices<Ghre_Survey, Ghre_SurveyDto, Ins |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult<long>> InsertData(InsertGhre_SurveyExtend insertModel) |
|
|
|
|
public async Task<ServiceResult<long>> InsertData(long id, InsertGhre_SurveyExtend insertModel) |
|
|
|
|
{ |
|
|
|
|
var data = ServiceResult<long>.OprateSuccess("新增成功", id); |
|
|
|
|
if (id == 0) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var data = ServiceResult<long>.OprateSuccess("新增成功", 0); |
|
|
|
|
var insert = Mapper.Map(insertModel).ToANew<InsertGhre_SurveyInput>(); |
|
|
|
|
|
|
|
|
|
id = await Add(insert); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < insertModel.Questions.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var question = Mapper.Map(insertModel.Questions[i]).ToANew<Ghre_SurveyQuestion>(); |
|
|
|
|
//question.Id = SnowFlakeSingle.instance.getID(); |
|
|
|
|
|
|
|
|
|
//return ServiceResult<long>.OprateFailed("失败!"); |
|
|
|
|
question.SurveyId = id; |
|
|
|
|
var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < insertModel.Questions[i].Options.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var option = Mapper.Map(insertModel.Questions[i].Options[j]).ToANew<Ghre_SurveyOption>(); |
|
|
|
|
option.SurveyId = id; |
|
|
|
|
option.SurveyQuestionId = questionId; |
|
|
|
|
await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
data.Data = id; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
await Db.Deleteable<Ghre_SurveyQuestion>().Where(x => x.SurveyId == id).ExecuteCommandAsync(); |
|
|
|
|
await Db.Deleteable<Ghre_SurveyOption>().Where(x => x.SurveyId == id).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < insertModel.Questions.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var question = Mapper.Map(insertModel.Questions[i]).ToANew<Ghre_SurveyQuestion>(); |
|
|
|
|
//question.Id = SnowFlakeSingle.instance.getID(); |
|
|
|
|
|
|
|
|
|
question.SurveyId = id; |
|
|
|
|
var questionId = await Db.Insertable(question).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < insertModel.Questions[i].Options.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var option = Mapper.Map(insertModel.Questions[i].Options[j]).ToANew<Ghre_SurveyOption>(); |
|
|
|
|
option.SurveyId = id; |
|
|
|
|
option.SurveyQuestionId = questionId; |
|
|
|
|
await Db.Insertable(option).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
data.Message = "修改成功!"; |
|
|
|
|
} |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|