コード例 #1
0
        public async Task <IActionResult> Post(Teacher model)
        {
            //   Teacher teacher = _mapper.Map<Teacher>(model);

            //model.UnitTeachers = null;
            _context.Add(model);

            if (await _repo.SaveChangesAsync())
            {
                return(Created($"api/teachers/{model.Id}", model));
            }
            return(NotFound());
        }
コード例 #2
0
ファイル: UnitsController.cs プロジェクト: NSTI2020/School
        public async Task <IActionResult> Post(Unit model)
        {
            try
            {
                if (model == null)
                {
                    return(NotFound());
                }
                //    Unit unit = model;
                //    unit.Address = model.Address;
                //    unit.Contact = model.Contact;



                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"api/units/{model.Id}", model));
                }
            }
            catch (System.Exception msg)
            {
                this.StatusCode(StatusCodes.Status500InternalServerError, $"A base de dados falhou. Erro: {msg.Message}");
            }
            return(Ok(model));
        }