Beispiel #1
0
        public async Task <IActionResult> PostAttachSurveysAsync([FromBody] AttachSurveys command)
        {
            await rules
            .MustBeValidLayoutId()
            .Apply(command, ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await service.Execute(command);

            //really should return a 201 created, but we have no API for getting the survey object yet
            return(Ok());
        }
Beispiel #2
0
        public async Task Execute(AttachSurveys command)
        {
            HashSet <Data.Survey> surveysToAdd = new HashSet <Data.Survey>();

            foreach (var icd9 in command.ICD9Code)
            {
                surveysToAdd.Add(new Data.Survey
                {
                    IdSurvey        = (int)await sequencerGenerator.GetNextAsync(SequenceType.Survey),
                    UID             = Guid.NewGuid(),
                    CdIcd9          = icd9,
                    IdSurveyVersion = 1,
                    CdSurveyType    = command.SurveyType,
                    DtEffective     = command.EffectiveDate,
                    UidLayout       = command.LayoutId,
                    NmSurvey        = command.Name
                });
            }

            foreach (var outbreakId in command.OutbreakId)
            {
                surveysToAdd.Add(new Data.Survey
                {
                    IdSurvey        = (int)await sequencerGenerator.GetNextAsync(SequenceType.Survey),
                    UID             = Guid.NewGuid(),
                    IdOutbreak      = outbreakId,
                    CdSurveyType    = command.SurveyType,
                    DtEffective     = command.EffectiveDate,
                    IdSurveyVersion = 1,
                    UidLayout       = command.LayoutId,
                    NmSurvey        = command.Name
                });
            }

            await writeContext.Survey.AddRangeAsync(surveysToAdd);

            await writeContext.SaveChangesAsync();
        }