Beispiel #1
0
        public IActionResult Create([FromBody] FieldViewModel field)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Field _newField = Mapper.Map <FieldViewModel, Field>(field);

            _newField.DateCreated = DateTime.Now;

            _fieldRepository.Add(_newField);
            _fieldRepository.Commit();

            field = Mapper.Map <Field, FieldViewModel>(_newField);

            CreatedAtRouteResult result = CreatedAtRoute("GetField", new { controller = "Fields", id = field.Id }, field);

            return(result);
        }