示例#1
0
        public async Task <ActionResult> ProvisionWorkflowPost()
        {
            var token = await O365Util.GetAccessToken(ServiceResources.Dashboard);

            var suiteLevelWebAppUrl = Regex.Match(Request.Url.AbsoluteUri, "https?://[^/]+?(?=/)", RegexOptions.Compiled).Value;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token))
            {
                var service       = new WorkflowProvisionService(clientContext);
                var incidentsList = CSOMUtil.getListByTitle(clientContext, "Incidents");

                service.Unsubscribe(incidentsList.Id, "Incident");
                service.DeleteDefinitions("Incident");
                service.DeleteList("Incident Workflow Tasks");
                service.DeleteList("Incident Workflow History");

                var workflow = System.IO.File.ReadAllText(Server.MapPath("~/Workflows/Incident.xaml"));

                workflow = workflow.Replace("(SuiteLevelWebAppUrlPlaceholder)", suiteLevelWebAppUrl)
                           .Replace("(dispatcherPlaceHolder)", ConfigurationManager.AppSettings["DispatcherName"]);
                workflow = WorkflowUtil.TranslateWorkflow(workflow);
                var definitionId  = service.SaveDefinitionAndPublish("Incident", workflow);
                var taskListId    = service.CreateTaskList("Incident Workflow Tasks");
                var historyListId = service.CreateHistoryList("Incident Workflow History");
                service.Subscribe("Incident Workflow", definitionId, incidentsList.Id, WorkflowSubscritpionEventType.ItemAdded, taskListId, historyListId);

                ViewBag.Message = "Incident Workflow, Incident Workflow Tasks list and Incident Workflow History list have been created successfully. Click the Create Sample Data menu item to proceed.";
            }
            return(View());
        }
示例#2
0
        public async Task <ActionResult> AuditRepair(string button, DashboardInspectionDetailsViewModel model)
        {
            var outlookToken = await O365Util.GetAccessToken(Capabilities.Mail);

            var sharePointToken = await O365Util.GetAccessToken(ServiceResources.DemoSite);

            var outlookClient = await O365Util.GetOutlookClient(Capabilities.Mail);

            Dashboard dashboardModel = new Dashboard(sharePointToken);

            var result = button == "Approve" ? ApprovalResult.Approved : ApprovalResult.Rejected;

            var tasksService = new TasksService(sharePointToken);
            await tasksService.CompleteRepairApprovalTask(model.incidentId, result);

            if (result == ApprovalResult.Approved)
            {
                await dashboardModel.ApproveRepair(model.incidentId);

                //This is the pattern you would use to send email from O365 APIs.  These emails are sent via the mobile apps.
                //var emailService = new EmailService(sharePointToken, Server.MapPath("/"));
                //var emailMessage = await emailService.ComposeRepairCompletedEmailMessage(model.incidentId);
                //await outlookClient.Me.SendMailAsync(emailMessage, true);
            }
            return(new RedirectResult("/Dashboard/Index"));
        }
示例#3
0
        public async Task <ActionResult> ProvisionWorkflow(string message)
        {
            await O365Util.GetAccessToken(ServiceResources.Dashboard); // Prepare token in advance.

            ViewBag.Message = message;
            return(View());
        }
        // GET: O365Calendar
        public async Task <ActionResult> Index()
        {
            List <CalendarEvent> myEvents = new List <CalendarEvent>();

            // Call the GetExchangeClient method, which will authenticate
            // the user and create the ExchangeClient object.
            var client = await O365Util.GetOutlookClient(Capabilities.Calendar);

            // Use the ExchangeClient object to call the Calendar API.
            // Get all events that have an end time after now.
            var eventsResults = await(from i in client.Me.Events
                                      //where i.End >= DateTimeOffset.UtcNow
                                      select i).Take(10).ExecuteAsync();

            // Order the results by start time.
            var events = eventsResults.CurrentPage.OrderBy(e => e.Start);

            // Create a CalendarEvent object for each event returned
            // by the API.
            foreach (Event calendarEvent in events)
            {
                CalendarEvent newEvent = new CalendarEvent();
                newEvent.Subject  = calendarEvent.Subject;
                newEvent.Location = new CalendarEventLocation {
                    DisplayName = calendarEvent.Location.DisplayName
                };
                newEvent.Start = calendarEvent.Start.GetValueOrDefault().DateTime;
                newEvent.End   = calendarEvent.End.GetValueOrDefault().DateTime;

                myEvents.Add(newEvent);
            }
            return(View(myEvents));
        }
示例#5
0
        public async Task <ActionResult> SendEmailTest(int incidentId)
        {
            var outlookToken = await O365Util.GetAccessToken(Capabilities.Mail);

            var sharePointToken = await O365Util.GetAccessToken(ServiceResources.DemoSite);

            return(await SendEmail(outlookToken, sharePointToken, incidentId));
        }
示例#6
0
        public async Task <ActionResult> Property(int Id)
        {
            var sharePointToken = await O365Util.GetAccessToken(ServiceResources.DemoSite);

            Dashboard dashboardModel = new Dashboard(sharePointToken);
            var       model          = await dashboardModel.GetDashboardPropertiesViewModel(Id);

            return(View(model));
        }
示例#7
0
        public async Task <ActionResult> SendEmail(string outlookToken, string sharePointToken, int incidentId)
        {
            var outlookClient = await O365Util.GetOutlookClient(Capabilities.Mail);

            var service = new EmailService(sharePointToken, Server.MapPath("/"));
            var message = await service.ComposeRepairCompletedEmailMessage(incidentId);

            await outlookClient.Me.SendMailAsync(message, true);

            return(Content("Success"));
        }
示例#8
0
        public async Task <ActionResult> ProvisionSiteComponents()
        {
            string token = await O365Util.GetAccessToken(ServiceResources.Dashboard);

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token))
            {
                SiteProvisioning siteProvisioning = new SiteProvisioning(clientContext);
                siteProvisioning.AddSiteComponents();
                //siteProvisioning.RemoveSiteComponents();
                ViewBag.Message = "The demo site collection has been created successfully.  Click the Provision Workflow menu item to proceed.";
            }
            return(View());
        }
示例#9
0
        public async Task <ActionResult> Index()
        {
            string token = await O365Util.GetAccessToken(ServiceResources.Admin);

            //Determine if the site collection used for the demo is already created
            using (var adminClientContext = TokenHelper.GetClientContextWithAccessToken(AdminServiceResourceId, token))
            {
                switch (CSOMUtil.GetSiteCollectionStatusByUrl(adminClientContext, DemoSiteCollectionUrl))
                {
                case "Active":
                    ViewBag.refresh = string.Empty;
                    ViewBag.Message = "The demo site collection was successfully created.  Proceeding to provision information architecture and content.  This process may take several minutes, please be patient and do not refresh the page during this process.  If you are eager to see the progress you may browse to the new site collection in your browser and inspect the new components as they are provisioned.";

                    return(new RedirectResult("/O365SiteProvisioning/ProvisionSiteComponents"));

                case "Creating":
                    ViewBag.refresh  = "refresh";
                    ViewBag.Message += DateTime.Now.ToString() + " - The demo site collection is being created.  The page will be refreshed automatically to check status.  This operation can take up to 20 minutes to complete.";
                    break;

                case "None":
                    try
                    {
                        CSOMUtil.CreateSiteCollection(adminClientContext, new SiteCreationProperties
                        {
                            Url                  = DemoSiteCollectionUrl,
                            Owner                = DemoSiteCollectionOwner,
                            Template             = "BLANKINTERNETCONTAINER#0",
                            Title                = "Contoso Property Management Dashboard",
                            StorageMaximumLevel  = 1000,
                            StorageWarningLevel  = 750,
                            TimeZoneId           = 7,
                            UserCodeMaximumLevel = 1000,
                            UserCodeWarningLevel = 500
                        });

                        ViewBag.refresh           = "refresh";
                        ViewBag.Message           = "The demo site collection is being created, please wait a few minutes, and the page will be refreshed automatically to check status.";
                        ViewBag.serviceResourceId = AdminServiceResourceId;
                    }
                    catch (Exception el)
                    {
                        ViewBag.refresh = "";
                        ViewBag.Message = el.Message + " If the Site Collection still exists in the Recycle Bin use the SharePoint Online Management Shell to delete it completely. Remove-SPODeletedSite -Identity <Site Collection URL>";
                    }
                    break;
                }
            }

            return(View());
        }
        public async Task <JsonResult> GetAvailableTimeSlots(string localTimeUtc)
        {
            // Call the GetExchangeClient method, which will authenticate
            // the user and create the ExchangeClient object.
            var client = await O365Util.GetOutlookClient(Capabilities.Calendar);

            //Get the Utc time from 9 AM to 6 PM
            DateTime startLocalTimeUtc = Convert.ToDateTime(localTimeUtc).ToUniversalTime();
            var      beginTime         = startLocalTimeUtc.AddHours(9);
            var      endTime           = startLocalTimeUtc.AddHours(18);

            //Get all time slot that we need within 9AM - 6 PM
            List <TimeSlot> timeSlots = new List <TimeSlot>();

            for (var i = 9; i < 18; i++)
            {
                TimeSlot timeSlot = new TimeSlot
                {
                    Start = i,
                    Value = string.Format("{0}:00 - {1}:00", i, i + 1)
                };
                timeSlots.Add(timeSlot);
            }

            List <CalendarEvent> myEvents = new List <CalendarEvent>();

            // Use the ExchangeClient object to call the Calendar API.
            // Get all events that have an end time after now.
            var eventsResults = await(from i in client.Me.Events
                                      where ((i.Start >= beginTime && i.Start <= endTime) || (i.End >= beginTime && i.End <= endTime) || (i.Start <= beginTime && i.End >= endTime))
                                      select i).Take(10).ExecuteAsync();

            // Order the results by start time.
            var events = eventsResults.CurrentPage.OrderBy(e => e.Start);

            // Create a CalendarEvent object for each event returned
            // by the API.
            foreach (Event calendarEvent in events)
            {
                if (calendarEvent.ShowAs == FreeBusyStatus.Busy)
                {
                    var Start = calendarEvent.Start.GetValueOrDefault().DateTime;
                    var End   = calendarEvent.End.GetValueOrDefault().DateTime;

                    //Remove all time slot which is between Start and End
                    RemoveBusyTime(startLocalTimeUtc, timeSlots, Start, End);
                }
            }

            return(Json(timeSlots, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Index(int Id)
        {
            var token = await O365Util.GetAccessToken(ServiceResources.DemoSite);

            MailAFOModel dashboardModel = new MailAFOModel(token);
            var          model          = await dashboardModel.GetMailAFOViewModel(Id);

            if (model == null)
            {
                return(new RedirectResult("/MailAFO/Index"));
            }

            return(View(model));
        }
示例#12
0
        public async Task <ActionResult> InspectionDetails(DashboardInspectionDetailsViewModel model)
        {
            var sharePointToken = await O365Util.GetAccessToken(ServiceResources.DemoSite);

            var service = new TasksService(sharePointToken);
            await service.CompleteRepairAssignmentTask(model.incidentId);

            var dashboardModel = new Dashboard(sharePointToken);
            var calendarEvent  = await dashboardModel.ScheduleRepair(model);

            await O365CalendarController.Create(calendarEvent);

            return(RedirectToAction("InspectionDetails", new { id = model.incidentId }));
        }
示例#13
0
        public async Task <ActionResult> CreateDemoData(SuiteLevelWebApp.Models.ProvisionDemoData model)
        {
            string token = await O365Util.GetAccessToken(ServiceResources.Dashboard);

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token))
            {
                AuthenticationHelper adHelp = new AuthenticationHelper();
                await adHelp.CreateADUsersAndGroups();

                SiteProvisioning siteProvisioning = new SiteProvisioning(clientContext);
                siteProvisioning.AddSiteContents();
                siteProvisioning.UpdateInspectionListItem(model.dateDemo);

                model.Message        = "The AAD Groups, AAD Users, and demo data have been created successfully.  The initial password for all the users is: TempP@ssw0rd!";
                TempData["datetime"] = model;
                return(RedirectToAction("ProvisionDemoData"));
            }
        }
示例#14
0
        public async Task <ActionResult> InspectionDetails(int Id)
        {
            await O365Util.GetAccessToken(Capabilities.Mail); // Prepare Outlook token in advance.

            var sharePointToken = await O365Util.GetAccessToken(ServiceResources.DemoSite);

            Dashboard dashboardModel = new Dashboard(sharePointToken);
            var       model          = await dashboardModel.GetDashboardInspectionDetailsViewModel(Id);

            if (model == null)
            {
                return(new RedirectResult("/Dashboard/Index"));
            }
            else if (model.viewName == "schedule a repair")
            {
                ViewBag.RepairPeopleList = new SelectList(model.repairPeople, "sl_emailaddress", "Title");
            }
            return(View(model));
        }
        public static async Task Create(Event newEvent)
        {
            var client = await O365Util.GetOutlookClient(Capabilities.Calendar);

            await client.Me.Events.AddEventAsync(newEvent);
        }