Beispiel #1
0
        public async Task <IActionResult> UpdateExplorer(string id, [FromBody] UpdateExplorerViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);
                    return(BadRequest(ModelState));
                }

                var res = await explorersService.UpdateExplorer(id, model);

                if (!res.Succeeded)
                {
                    ModelState.TryAddModelError("NoUser", "Explorer not found.");
                    return(new BadRequestObjectResult(ModelState));
                }

                return(new OkObjectResult("Captain has been updated succesfully"));
            }
            catch (Exception exc)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IdentityResult> UpdateExplorer(string id, UpdateExplorerViewModel explorerData)
        {
            User explorer = await userManager.FindByIdAsync(id);

            if (explorer != null)
            {
                explorer.Name     = explorerData.Name;
                explorer.UserName = explorerData.UserName;

                return(await userManager.UpdateAsync(explorer));
            }

            return(IdentityResult.Failed(new IdentityError()
            {
                Code = "userNotFound", Description = "user not found"
            }));
        }