Esempio n. 1
0
        public async Task <Hero> UpdateByIdAsync(
            Guid id,
            HeroUpdateOptions heroUpdateOptions)
        {
            var heroDocument =
                await _heroDocumentStore.FetchByIdAsync(
                    id);

            if (heroDocument == null)
            {
                throw new NullReferenceException("Hero does not exist.");
            }

            heroDocument.Name         = heroUpdateOptions.Name;
            heroDocument.Gender       = heroUpdateOptions.Gender;
            heroDocument.Affiliations = heroUpdateOptions.Affiliations;
            heroDocument.Powers       = heroUpdateOptions.Powers;
            heroDocument.Notes        = heroUpdateOptions.Notes;

            heroDocument =
                await _heroDocumentStore.UpdateByIdAsync(
                    id,
                    heroDocument);

            var hero =
                new Hero(heroDocument);

            return(hero);
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateByIdAsync(
            [FromRoute] Guid id,
            [SwaggerParameter(Required = true)] HeroUpdateOptions heroUpdateOptions)
        {
            var hero =
                await _heroService.UpdateByIdAsync(
                    id,
                    heroUpdateOptions);

            if (hero == null)
            {
                return(NotFound());
            }

            return(Ok(hero));
        }