Пример #1
0
        public PositionGetDto CreatePosition(PositionCreateDto positionCreateDto)
        {
            var position = new Position
            {
                Name = positionCreateDto.Name
            };

            _context.Set <Position>().Add(position);
            _context.SaveChanges();

            var positionGetDto = new PositionGetDto
            {
                Id   = position.Id,
                Name = position.Name
            };

            return(positionGetDto);
        }
        public async Task <IActionResult> AddPositionAsync(PositionCreateDto pos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Fill all fields"));
            }
            var position = _mapper.Map <Position>(pos);

            try
            {
                position = await _positionsService.CreateAsync(position);

                return(Created(Request.Path, position.Id));
            }
            catch (EntityPresentException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception)
            {
                return(this.ServerError("Failed to create position"));
            }
        }
Пример #3
0
        public IActionResult Post([FromBody] PositionCreateDto positionCreateDto)
        {
            var position = _positionRepository.CreatePosition(positionCreateDto);

            return(Created("[controller]", position));
        }