// Delete an event.
        public async Task <ActionResult> DeleteEvent(string id)
        {
            ResultsViewModel results = new ResultsViewModel();

            results.Selectable = false;
            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Delete the event.
                results.Items = await eventsService.DeleteEvent(graphClient, id);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }

                // Personal accounts that aren't enabled for the Outlook REST API get a "MailboxNotEnabledForRESTAPI" or "MailboxNotSupportedForRESTAPI" error.
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Events", results));
        }
示例#2
0
        public IActionResult Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            else
            {
                _eventService.DeleteEvent(id);
                return(Ok());
            }
        }
示例#3
0
        public async Task DeleteEventShouldDeleteTheCorrectEventAndCorrespondingPost()
        {
            await this.PopulateEvents();

            await this.PopulatePosts();

            var service = new EventsService(
                this.eventsRepository,
                this.postsService,
                this.postRepository);

            await service.DeleteEvent(2);

            var eventTo = this.eventsRepository.All().FirstOrDefault(e => e.Title == "ccc");
            var post    = this.postRepository.All().FirstOrDefault(p => p.Id == 2);

            Assert.Null(eventTo);
            Assert.Null(post);
        }
示例#4
0
        // Delete an event.
        public async Task <ActionResult> DeleteEvent(string id)
        {
            ResultsViewModel results = new ResultsViewModel(false);

            try
            {
                // Delete the event.
                results.Items = await eventsService.DeleteEvent(id);
            }
            catch (ServiceException se)
            {
                if ((se.InnerException as AuthenticationException)?.Error.Code == Resource.Error_AuthChallengeNeeded)
                {
                    HttpContext.Request.GetOwinContext().Authentication.Challenge();
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Events", results));
        }