public IActionResult CreateChild(string firstName, string lastName, DateTime dateOfBirth)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            var child = new ChildDto()
            {
                FirstName   = firstName,
                LastName    = lastName,
                DateOfBirth = dateOfBirth
            };

            var childToCreate = AutoMapper.Mapper.Map <Domain.Child>(child);

            _iRepo.Add(childToCreate);
            if (!_iRepo.Save())
            {
                return(StatusCode(500, "A problem happend while saving your request."));
            }
            var createdChild = AutoMapper.Mapper.Map <Models.ChildOnlyDto>(childToCreate);

            return(Ok(createdChild));
        }
示例#2
0
        public IActionResult CreateSleepingPeriod(int childId, DateTime from, DateTime to)
        {
            //if(sleepingPeriod == null)
            //{
            //    return BadRequest();
            //}
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var child = _iRepo.GetChildById(childId, false, false);

            if (child == null)
            {
                return(NotFound());
            }

            var sleepingPeriod = new SleepingPeriodForCreationDto()
            {
                ChildId = childId,
                Child   = child,
                From    = from,
                To      = to,
                TypeOfSleepingPeriod = SleepingPeriodForCreationDto.TypeOfSleepingPeriods.alright
            };

            var sleepingPeriodToCreate = AutoMapper.Mapper.Map <Domain.SleepingPeriod>(sleepingPeriod);

            _iRepo.AddSleepingPeriodByChildId(childId, sleepingPeriodToCreate);
            if (!_iRepo.Save())
            {
                return(StatusCode(500, "A problem happend while saving your request."));
            }
            var createdSleepingPeriod = AutoMapper.Mapper.Map <Models.SleepingPeriodDto>(sleepingPeriodToCreate);

            return(Ok(createdSleepingPeriod));
        }