Esempio n. 1
0
        public async Task <IActionResult> Create(CreateReadingViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var reading = _mapper.Map <Reading>(model);

            _db.Readings.Add(reading);
            await _db.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = reading.Id }, reading));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(CreateFoodViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var food = _mapper.Map <Food>(model);

            _db.Foods.Add(food);
            await _db.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = food.Id }, food));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(CreateInjectionViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var injection = _mapper.Map <InsulinInjection>(model);

            _db.Injections.Add(injection);
            await _db.SaveChangesAsync();

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