示例#1
0
        public ProgramSchedule AddNewProgramSchedule(CreateProgramScheduleDto dto)
        {
            var type = new CreateProgramTypeDto
            {
                Name = dto.TypeName,
            };

            _programTypeService.AddNewProgramType(type);
            var program = new ProgramSchedule
            {
                ProgramTypeId               = _programTypeService.GetProgramByName(type.Name).Id,
                FitnessProgramName          = dto.FitnessProgramName,
                NutritionProgramName        = dto.NutritionProgramName,
                FitnessProgramDescription   = dto.FitnessProgramDescription,
                NutritionProgramDescription = dto.NutritionProgramDescription
            };

            _programScheduleRepository.Add(program);
            _programScheduleRepository.Save();
            _programTypeService.UpdateProgramTypeDetails(program.ProgramTypeId, new UpdateProgramTypeDto
            {
                ScheduleId = program.Id
            });
            return(program);
        }
        public IActionResult Post([FromBody] CreateProgramTypeDto dto)
        {
            var programType = _programTypeService.AddNewProgramType(dto);

            if (programType == null)
            {
                return(BadRequest("ProgramType with such name already exists"));
            }

            var result = _mapper.Map <ProgramTypeDto>(programType);

            return(CreatedAtAction(nameof(Get), new { id = programType.Id }, result));
        }