コード例 #1
0
        public ActionResult <ConnectionReadDto> CreateConnection(ConnectionCreateDto connectionCreateDto)
        {
            Connection model = _mapper.Map <Connection>(connectionCreateDto);

            _repository.CreateConnection(model);
            _repository.SaveChanges();

            return(CreatedAtRoute(nameof(GetConnections), new { email = connectionCreateDto.AccepterEmail }, _mapper.Map <ConnectionReadDto>(model)));
        }
コード例 #2
0
        //[ServiceFilterAttribute(typeof(ValidationFilterAttribute))]
        public ActionResult <ApiResponse <ConnectionDto> > Create(ConnectionCreateDto item)
        {
            var response = new ApiResponse <ConnectionDto>();

            try
            {
                Connection user = _connectionRepository.Add(_mapper.Map <Connection>(item));
                response.Result = _mapper.Map <ConnectionDto>(user);
            }
            catch (Exception ex)
            {
                response.Result  = null;
                response.Success = false;
                response.Message = "Internal server error";
                _logger.LogError($"Something went wrong: { ex.ToString() }");
                return(StatusCode(500, response));
            }

            return(StatusCode(201, response));
        }