예제 #1
0
        public async Task <IActionResult> CreateForCurrentUser([FromBody] ArtistCreateDTO artistDTO)//added 16/05/2021 obtain user id
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Create Attempted");
                if (artistDTO == null)
                {
                    _logger.LogWarn($"{location}: Empty Request was submitted");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn($"{location}: Data was Incomplete");
                    return(BadRequest(ModelState));
                }
                var artist    = _mapper.Map <Artist>(artistDTO);
                var isSuccess = await _artistRepository.Create(artist);

                if (!isSuccess)
                {
                    return(InternalError($"{location}: Creation failed"));
                }
                _logger.LogInfo($"{location}: Creation was successful");
                return(Created("Create", new { artist }));
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} - {e.InnerException}"));
            }
        }
예제 #2
0
        public async Task <ArtistDTO> PutAsync(ArtistCreateDTO artist)
        {
            this.Logger.LogTrace("PutAsync called");

            var result = await this.ArtistCreateService.CreateAsync(this.Mapper.Map <ArtistUpdateModel>(artist));

            return(this.Mapper.Map <ArtistDTO>(result));
        }
        public ActionResult CreateArtist(ArtistCreateDTO artistDto)
        {
            if (artistDto == null)
            {
                throw new NotImplementedException("Artist not found");
            }
            var artist = _mapper.Map <Artist>(artistDto);

            _artistRepository.CreateArtist(artist);

            return(Ok(artist));
        }