Beispiel #1
0
        //[Authorize]
        public async Task <ActionResult> UpdateComposer(string id, ComposerToSaveResource composerToUpdate)
        {
            try
            {
                // Validation of input Data
                var validation       = new ComposerToSaveResourceValidator();
                var validationResult = await validation.ValidateAsync(composerToUpdate);

                if (!validationResult.IsValid)
                {
                    return(BadRequest(validationResult.Errors));
                }

                var composerExist = await _composerService.GetComposerById(id);

                if (composerExist == null)
                {
                    return(NotFound("Composer Not Found"));
                }

                // Mapping
                var composer = _mapperService.Map <ComposerToSaveResource, Composer>(composerToUpdate);

                // Update
                _composerService.UpdateCompser(id, composer);

                return(Ok("Composer Updated"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #2
0
        //[Authorize]
        public async Task <ActionResult <ComposerResource> > CreateComposer(ComposerToSaveResource composerToSave)
        {
            try
            {
                // Validation of input Data
                var validation       = new ComposerToSaveResourceValidator();
                var validationResult = await validation.ValidateAsync(composerToSave);

                if (!validationResult.IsValid)
                {
                    return(BadRequest(validationResult.Errors));
                }

                // Mapping
                var composer = _mapperService.Map <ComposerToSaveResource, Composer>(composerToSave);

                // Creation
                var composerCreated = await _composerService.CreateComposer(composer);

                // Mapping
                var composerResource = _mapperService.Map <Composer, ComposerResource>(composerCreated);

                return(Ok(composerResource));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }