Example #1
0
        public async Task <IActionResult> CreateIteration([FromBody] List <IterationInfo> iterations)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //var iterationModel = _mapper.Map<List<Services.Entities.SurveyIteration>>(iteration);

            var iterationModel = (from iteration in iterations
                                  select new Services.Entities.SurveyIteration
            {
                Id = Guid.NewGuid().ToString(),
                IterationName = iteration.IterationName,
                OpenDateTime = iteration.OpenDateTime,
                CloseDateTime = iteration.CloseDateTime,
                ReminderDateTime = iteration.ReminderDateTime,
                ReminderFrequency = iteration.ReminderFrequency,
                SurveyId = iteration.SurveyId
            }).ToList();

            var result = await _iterationRepository.CreateIteration(iterationModel);

            if (result)
            //if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(new OkObjectResult(iterationModel));
            }
            else
            {
                return(BadRequest());
            }
        }
Example #2
0
        public async Task <ActionResult> CreateIteration(IterationCreationUpdateDto model)
        {
            var iterationEntity = _mapper.Map <Iteration>(model);

            _iterationRepository.CreateIteration(iterationEntity);

            var iterationToReturn = _mapper.Map <IterationDto>(iterationEntity);

            if (await _iterationRepository.SaveAllAsync())
            {
                return(CreatedAtRoute("GetIteration", new { id = iterationEntity.Id }, iterationToReturn));
            }

            return(BadRequest());
        }