コード例 #1
0
        public async Task AddAsync([FromBody] InstrumentEditModel model)
        {
            try
            {
                var instrument = Mapper.Map <Instrument>(model);

                await _instrumentService.AddAsync(instrument);
            }
            catch (InvalidOperationException exception)
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, exception.Message);
            }
        }
コード例 #2
0
        public async Task AddAsync([FromBody] InstrumentModel model, string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ValidationApiException("Used id required");
            }

            try
            {
                var instrument = Mapper.Map <Instrument>(model);

                await _instrumentService.AddAsync(instrument, userId);
            }
            catch (EntityAlreadyExistsException)
            {
                throw new ValidationApiException(HttpStatusCode.Conflict, "Instrument already exists.");
            }
        }