Exemple #1
0
        // GET: TodoList/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            try
            {
                Todo todo = await this._todoListService.GetAsync(id);

                if (todo == null)
                {
                    return(NotFound());
                }
                return(View(todo));
            }
            catch (WebApiMsalUiRequiredException hex)
            {
                // Challenges the user if exception is thrown from Web API.
                try
                {
                    var claimChallenge = ExtractAuthenticationHeader.ExtractHeaderValues(hex);
                    _consentHandler.ChallengeUser(new string[] { "user.read" }, claimChallenge);

                    return(new EmptyResult());
                }
                catch (Exception ex)
                {
                    _consentHandler.HandleException(ex);
                }

                Console.WriteLine(hex.Message);
            }
            return(View());
        }
Exemple #2
0
        public async Task <ActionResult> Create([Bind("Title,Owner")] Todo todo)
        {
            try
            {
                await _todoListService.AddAsync(todo);
            }
            catch (WebApiMsalUiRequiredException hex)
            {
                // Challenges the user if exception is thrown from Web API.
                try
                {
                    var claimChallenge = ExtractAuthenticationHeader.ExtractHeaderValues(hex);
                    _consentHandler.ChallengeUser(new string[] { "user.read" }, claimChallenge);

                    return(new EmptyResult());
                }
                catch (Exception ex)
                {
                    _consentHandler.HandleException(ex);
                }

                Console.WriteLine(hex.Message);
            }
            return(RedirectToAction("Index"));
        }