// Get the current user's photo.
        public async Task <ActionResult> GetMyPhoto()
        {
            ResultsViewModel results = new ResultsViewModel();

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

                // Get my photo.
                results.Items = await usersService.GetMyPhoto(graphClient);
            }

            // Throws exception if photo is null, with itemNotFound code.
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Users", results));
        }
        // Get a specified user's photo.
        public async Task <ActionResult> GetUserPhoto(string id)
        {
            ResultsViewModel results = new ResultsViewModel();

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

                // Get the user's photo.
                results.Items = await usersService.GetUserPhoto(graphClient, id);
            }

            // Throws an exception when requesting the photo for unlicensed users (such as those created by this sample), with message "The requested user '<user-name>' is invalid."
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Users", results));
        }
Пример #3
0
        public async Task <ActionResult> Delete()
        {
            EventsItem results = new EventsItem();

            try
            {
                var id = Request.Form["Id"];
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Delete the event.
                results = 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(RedirectToAction("Index", "Student").Success("Event Deleted"));
        }
Пример #4
0
        public async Task GetChangedMessagesAsync(IEnumerable <Notification> notifications, Cache cache)
        {
            List <Microsoft.Graph.Message> messages = new List <Microsoft.Graph.Message>();

            foreach (var notification in notifications)
            {
                // Get the userObjectId from the cached SubscriptionData and create a Graph SDK authenticated client
                var subscriptionData = (SubscriptionData)cache.Get("subscriptionId_" + notification.SubscriptionId);
                var graphClient      = SDKHelper.GetAuthenticatedClient(subscriptionData.userObjectId);

                var request = new BaseRequest($"{graphClient.BaseUrl}/{notification.Resource}", graphClient);
                request.ContentType = "application/json";

                var response = await request.SendRequestAsync(null, CancellationToken.None).ConfigureAwait(continueOnCapturedContext: false);

                // Get the messages from the JSON response.
                string stringResult = await response.Content.ReadAsStringAsync();

                var type = notification.ResourceData.ODataType;
                if (type == "#Microsoft.Graph.Message")
                {
                    messages.Add(JsonConvert.DeserializeObject <Microsoft.Graph.Message>(stringResult));
                }
            }

            if (messages.Count > 0)
            {
                NotificationService notificationService = new NotificationService();
                notificationService.SendNotificationToClient(messages);
            }
        }
        // Update the content of a file in the user's root directory.
        // This snippet replaces the text content of a .txt file.
        public async Task <ActionResult> UpdateFileContent(string id)
        {
            ResultsViewModel results = new ResultsViewModel();

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

                // Get the file. Make sure it's a .txt file (for the purposes of this snippet).
                results.Items = await filesService.UpdateFileContent(graphClient, id);

                // Handle selected item is not supported.
                foreach (var item in results.Items)
                {
                    if (item.Properties.ContainsKey(Resource.File_ChooseTextFile))
                    {
                        results.Selectable = false;
                    }
                }
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Files", results));
        }
Пример #6
0
        public async Task <ActionResult> CreateMessage([Bind(Include = "student_id,student_Name,message")] Models.StudentMessage message)
        {
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
            var userDetails = await eventsService.GetMyDetails(graphClient);

            StudentMessage msg = new StudentMessage();

            msg.student_id   = userDetails.Mail ?? userDetails.UserPrincipalName;
            msg.student_Name = userDetails.DisplayName;
            msg.message      = Request.Form["message"];
            msg.Date_Created = DateTime.Now;
            msg.is_archived  = false;
            OfficeHoursContext officeHoursContext = new OfficeHoursContext();
            List <Faculty>     faculties          = officeHoursContext.faculties.ToList();

            msg.Email = Session["facultyMail"].ToString();
            try
            {
                officeHoursContext.messages.Add(msg);
                officeHoursContext.SaveChanges();
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.)
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }

            return(RedirectToAction("MessageView", "Student").Success("Message created and sent to faculty"));
        }
 public EventController()
 {
     graphClient                = SDKHelper.GetAuthenticatedClient();
     graphService               = new GraphService(graphClient);
     managedEventRepository     = new ManagedEventRepository(graphClient);
     schemaExtensionsRepository = new SchemaExtensionsRepository(graphClient);
 }
Пример #8
0
        public async Task <List <Message> > SyncInbox()
        {
            GraphServiceClient graphClient                   = SDKHelper.GetAuthenticatedClient();
            List <Message>     messagesCollection            = new List <Message>();
            IMailFolderMessagesCollectionRequest nextRequest = null;

            do
            {
                IMailFolderMessagesCollectionPage messagesCollectionPage;
                if (nextRequest != null)
                {
                    messagesCollectionPage = await nextRequest.GetAsync();
                }
                else
                {
                    messagesCollectionPage = await graphClient.Me.MailFolders.Inbox.Messages.Request()
                                             .Select("Subject,ReceivedDateTime,From,BodyPreview,IsRead")
                                             .OrderBy("ReceivedDateTime+desc")
                                             .Filter("ReceivedDateTime ge " + DateTime.Now.AddDays(-7).ToString("yyyy-MM-ddTHH:mm:ssZ")).GetAsync();
                }
                messagesCollection.AddRange(messagesCollectionPage.CurrentPage);
                if (messagesCollectionPage.CurrentPage.Count == 0)
                {
                    nextRequest = null;
                }
                else
                {
                    nextRequest = messagesCollectionPage.NextPageRequest;
                }
            }while (nextRequest != null);
            return(messagesCollection);
        }
Пример #9
0
        public async Task <ActionResult> DeleteOpenExtensionForMe()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                await extensionsService.DeleteOpenExtensionForMe(graphClient, extensionName);

                results.Items = new List <ResultsItem>()
                {
                    new ResultsItem()
                    {
                        Display = $"{extensionName} {Resource.Extensions_deleted}"
                    }
                };
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }

            return(View("Extensions", results));
        }
Пример #10
0
        public async Task <ActionResult> UpdateOpenExtensionForMe()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // For updating a single dictionary item, you would first need to retrieve & then update the extension
                await extensionsService.UpdateOpenExtensionForMe(graphClient,
                                                                 extensionName,
                                                                 new Dictionary <string, object>()
                                                                 { { "theme", "light" }, { "color", "yellow" }, { "lang", "Swahili" } });

                results.Items = new List <ResultsItem>()
                {
                    new ResultsItem()
                    {
                        Display = $"{extensionName} {Resource.Extensions_updated}"
                    }
                };
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }

            return(View("Extensions", results));
        }
Пример #11
0
        // Get the drive items in the root directory of the current user's default drive.
        //public async Task<ActionResult> GetMyFilesAndFolders()
        //{
        //    ResultsViewModel results = new ResultsViewModel();
        //    try
        //    {

        //        // Initialize the GraphServiceClient.
        //        GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

        //        // Get the files and folders in the current user's drive.
        //        results.Items = await filesService.GetMyFilesAndFolders(graphClient);
        //    }
        //    catch (ServiceException se)
        //    {
        //        if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
        //        return RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) });
        //    }
        //    return View("Files", results);
        //}

        //// Get the items that are shared with the current user.
        //public async Task<ActionResult> GetSharedWithMe()
        //{
        //    ResultsViewModel results = new ResultsViewModel(false);
        //    try
        //    {

        //        // Initialize the GraphServiceClient.
        //        GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

        //        // Get the shared items.
        //        results.Items = await filesService.GetSharedWithMe(graphClient);
        //    }
        //    catch (ServiceException se)
        //    {
        //        if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
        //        return RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) });

        //    }
        //    return View("Files", results);
        //}

        //// Get the current user's default drive.
        //public async Task<ActionResult> GetMyDrive()
        //{
        //    ResultsViewModel results = new ResultsViewModel(false);
        //    try
        //    {

        //        // Initialize the GraphServiceClient.
        //        GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

        //        // Get the current user's default drive.
        //        results.Items = await filesService.GetMyDrive(graphClient);
        //    }
        //    catch (ServiceException se)
        //    {
        //        if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
        //        return RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) });
        //    }
        //    return View("Files", results);
        //}

        //// Create a text file in the current user's root directory.
        //public async Task<ActionResult> CreateFile()
        //{
        //    ResultsViewModel results = new ResultsViewModel();

        //    try
        //        {

        //            // Initialize the GraphServiceClient.
        //            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

        //            // Add the file.
        //            results.Items = await filesService.CreateFile(graphClient);
        //        }
        //        catch (ServiceException se)
        //        {
        //            if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
        //            return RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) });
        //        }
        //    return View("Files", results);
        //}

        //// Create a folder in the current user's root directory.
        //public async Task<ActionResult> CreateFolder()
        //{
        //    ResultsViewModel results = new ResultsViewModel();
        //    try
        //    {

        //        // Initialize the GraphServiceClient.
        //        GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

        //        // Add the folder.
        //        results.Items = await filesService.CreateFolder(graphClient);
        //    }
        //    catch (ServiceException se)
        //    {
        //        if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
        //        return RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) });
        //    }
        //    return View("Files", results);
        //}

        // Upload a BMP file to the current user's root directory.
        public async Task <ActionResult> UploadLargeFile()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient("7890");

                // Add the file.
                results.Items = await filesService.UploadLargeFile(graphClient);



                // FOR TEST
                GraphServiceClient graphClient3 = SDKHelper.GetAuthenticatedClient("7877");
                await filesService.UploadLargeFile(graphClient3);

                // FOR TEST
                GraphServiceClient graphClient2 = SDKHelper.GetAuthenticatedClient("7891");
                await filesService.UploadLargeFile(graphClient2);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Files", results));
        }
Пример #12
0
        public EventsController()
        {
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

            eventsService = new EventsService(graphClient);
        }
        // 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));
        }
        // Send mail on behalf of the current user.
        public async Task <ActionResult> SendEmail()
        {
            if (string.IsNullOrEmpty(Request.Form["email-address"]))
            {
                ViewBag.Message = Resource.Graph_SendMail_Message_GetEmailFirst;
                return(View("Graph"));
            }

            // Build the email message.
            Message message = graphService.BuildEmailMessage(Request.Form["recipients"], Request.Form["subject"]);

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

                // Send the email.
                await graphService.SendEmail(graphClient, message);

                // Reset the current user's email address and the status to display when the page reloads.
                ViewBag.Email   = Request.Form["email-address"];
                ViewBag.Message = Resource.Graph_SendMail_Success_Result;
                return(View("Graph"));
            }
            catch (ServiceException se)
            {
                if (se.Error.Code == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = Resource.Error_Message + Request.RawUrl + ": " + se.Error.Message }));
            }
        }
        public async Task <ActionResult> Email()
        {
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

            ViewBag.Email = await graphService.GetMyEmailAddress(graphClient);

            return(View());
        }
 /// <summary>
 /// Initialize the graphClient
 /// </summary>
 public GraphService()
 {
     graphClient = SDKHelper.GetAuthenticatedClient();
     if (graphClient != null)
     {
         graphClient.BaseUrl = GraphBetaBaseUrl;
     }
 }
 /// <summary>
 /// Initialize the graphClient
 /// </summary>
 public GraphService()
 {
     graphClient = SDKHelper.GetAuthenticatedClient();
     if (graphClient != null)
     {
         graphClient.BaseUrl = ConfigurationManager.AppSettings["GraphBaseUrl"];
     }
 }
Пример #18
0
        public async Task <ActionResult> SavePhoto()
        {
            byte[] byteArray;
            if (Session["dump"] == null)
            {
                return(RedirectToAction("Index", "Error", new { message = string.Format("Try capturing the image again") }));
            }
            byteArray = String_To_Bytes2(Session["dump"].ToString());
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
            var userDetails = await eventsService.GetMyDetails(graphClient);

            var result = await filesService.CreateFile(graphClient, byteArray);

            try
            {
                CaptureNote captureNote = new CaptureNote()
                {
                    CapturedDate = DateTime.Now,
                    Email        = Session["facultyMail"] != null ? Session["facultyMail"].ToString() : "",
                    NoteLink     = result.Display,
                    StudentName  = userDetails.DisplayName,
                };

                try
                {
                    db.captureNotes.Add(captureNote);
                    var val = db.SaveChanges();
                    if (val != 0)
                    {
                        var path = Server.MapPath("~/WebImages/");
                        System.IO.DirectoryInfo di = new DirectoryInfo(path);

                        foreach (FileInfo file in di.GetFiles())
                        {
                            file.Delete();
                        }
                    }
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.)
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            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(RedirectToAction("Index", "Student").Success("Note captured successfully."));
        }
Пример #19
0
        //public async Task<ActionResult> GoToRegister(CompanyLicenseViewModel cModel)
        public async Task <ActionResult> GoToRegister()
        {
            GraphServiceClient graphClient1 = SDKHelper.GetAuthenticatedClient();
            IGraphServiceOrganizationCollectionPage organization = await graphService.GetOrganisationInfo(graphClient1);

            if (organization.Count == 0)
            {
                return(View("~/Views/Shared/GoToLogin.cshtml"));
            }

            GraphServiceClient graphClient2 = SDKHelper.GetAuthenticatedClient();

            // Get the current user's email address.
            //Microsoft.Graph.User me = await graphClient.Me.Request().Select("mail, userPrincipalName, displayName, jobTitle").GetAsync();
            Microsoft.Graph.User me = await graphService.GetUserInfo(graphClient2);

            //me.Mail ?? me.UserPrincipalName;
            string email       = me.Mail ?? me.UserPrincipalName;
            string displayName = me.DisplayName;
            string companyName = organization.CurrentPage[0].DisplayName;
            string website     = organization.CurrentPage[0].VerifiedDomains.ElementAt(0).Name; //me.MySite;
            string jobTitle    = me.JobTitle;

            RegistrationViewModel model = new RegistrationViewModel();

            model.EmailID       = email;
            model.CustomerName  = displayName;
            model.DomainName    = website;
            model.Name          = companyName;
            model.BusinessTitle = jobTitle;
            //model.CustomerType = cModel.CompanyLicenseType;
            model.CustomerType = "Premium";

            ViewBag.PageType = "Register";

            //ViewBag.citieslist = _cityRepository.GetAllElements().Select(x => new SelectListItem
            //{
            //    Value = x.CityName,
            //    Text = x.CityName
            //});


            ViewBag.countrieslist = _cityRepository.GetAllElements().Select(x => new { x.CountryName }).OrderBy(x => x.CountryName).ToList().Distinct().Select(x => new SelectListItem
            {
                Value = x.CountryName,
                Text  = x.CountryName
            });

            ViewBag.industrieslist = _industryRepository.GetAllElements().OrderBy(x => x.IndustryName).ToList().Select(x => new SelectListItem
            {
                Value = x.IndustryName,
                Text  = x.IndustryName
            });

            return(View("~/Views/Registration/Register.cshtml", model));
        }
 /// <summary>
 /// Initialize the graphClient
 /// </summary>
 public GraphService()
 {
     graphClient = SDKHelper.GetAuthenticatedClient();
     if (graphClient != null)
     {
         this.graphUrlVersion = ConfigurationManager.AppSettings["GraphUrlVersion"];
         this.graphUrl        = ConfigurationManager.AppSettings["GraphBaseUrl"] + this.graphUrlVersion;
         graphClient.BaseUrl  = this.graphUrl;
     }
 }
Пример #21
0
        public async Task <ActionResult> Edit()
        {
            EventsItem results = new EventsItem();

            try
            {
                var id             = Request.Form["Id"];
                var subject        = Request.Form["Subject"];
                var eventDate      = Request.Form["EventDate"];
                var eventStartTime = Request.Form["EventStart"];
                var eventEndTime   = Request.Form["EventEnd"];

                var eventdatetime = DateTime.Parse(eventDate);
                var startTimespan = DateTime.ParseExact(eventStartTime,
                                                        "hh:mm tt", CultureInfo.InvariantCulture);
                var endTimespan = DateTime.ParseExact(eventEndTime,
                                                      "hh:mm tt", CultureInfo.InvariantCulture);

                results = new EventsItem()
                {
                    Id        = id,
                    Subject   = subject,
                    StartTime = new DateTimeTimeZone
                    {
                        DateTime = new DateTime(eventdatetime.Year, eventdatetime.Month, eventdatetime.Day, startTimespan.Hour,
                                                startTimespan.Minute, startTimespan.Second).ToString("o"),
                        TimeZone = TimeZoneInfo.Local.Id
                    },
                    EndTime = new DateTimeTimeZone
                    {
                        DateTime = new DateTime(eventdatetime.Year, eventdatetime.Month, eventdatetime.Day, endTimespan.Hour,
                                                endTimespan.Minute, endTimespan.Second).ToString("o"),
                        TimeZone = TimeZoneInfo.Local.Id
                    },
                };

                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Update the event.
                results = await eventsService.UpdateEvent(graphClient, id, results);
            }
            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(RedirectToAction("Index", "Student").Success("Event edited successfully"));
        }
Пример #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphService" /> class
        /// </summary>
        public GraphService(AzureConfiguration azureConfig, string jwtToken)
        {
            _graphClient = SDKHelper.GetAuthenticatedClient(azureConfig, jwtToken);

            AccessToken = SDKHelper.GetAccessToken(azureConfig, jwtToken);

            JWTToken = jwtToken;

            if (_graphClient != null)
            {
                GraphUrlVersion      = azureConfig.UrlVersion;
                NotificationUri      = azureConfig.NotificationUri;
                GraphUrl             = azureConfig.BaseUrl + GraphUrlVersion;
                _graphClient.BaseUrl = GraphUrl;
            }
        }
Пример #23
0
        // Get the current user's email address from their profile.
        public async Task <ActionResult> GetMyEmailAddress()
        {
            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Get the current user's email address.
                ViewBag.Email = await graphService.GetMyEmailAddress(graphClient);

                return(View("Graph"));
            }
            catch (ServiceException se)
            {
                //if (se.Error.Message == Resource.Error_AuthChallengeNeeded) return new EmptyResult();
                return(RedirectToAction("Index", "Error", new { message = Resource.Error_Message + Request.RawUrl + ": " + se.Error.Message }));
            }
        }
Пример #24
0
        public async Task <ActionResult> MessageView()
        {
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
            User fac = await eventsService.GetMyDetails(graphClient);

            OfficeHoursContext    officeHoursContext     = new OfficeHoursContext();
            List <StudentMessage> studentMessages        = officeHoursContext.messages.ToList();
            List <WebApp.Models.StudentMessage> messages = new List <StudentMessage>();

            foreach (var st in studentMessages)
            {
                if (st.student_id.Equals(fac.Mail))
                {
                    messages.Add(st);
                }
            }
            return(View(messages));
        }
Пример #25
0
        // Get events.
        public async Task <ActionResult> Index()
        {
            List <EventsItem> results         = new List <EventsItem>();
            List <EventsItem> filteredResults = new List <EventsItem>();

            if (Session["facultyMail"] != null)
            {
                try
                {
                    // Initialize the GraphServiceClient.
                    GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                    // Get events.
                    results = await eventsService.GetMyAppointments(graphClient);

                    if (results != null && results.Any())
                    {
                        foreach (EventsItem item in results)
                        {
                            foreach (Attendee attendee in item.Attendees)
                            {
                                if (attendee.EmailAddress.Address.Equals(Session["facultyMail"].ToString()))
                                {
                                    filteredResults.Add(item);
                                }
                            }
                        }
                    }
                }
                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("Index", filteredResults));
            }
            return(RedirectToAction("Home", "Home"));
        }
Пример #26
0
        // Get the current user's photo from their profile.
        public async Task <ActionResult> GetMyPhoto()
        {
            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                ViewBag.Photo = await graphService.GetMyPhoto(graphClient);

                return(View("Graph"));
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = Resource.Error_Message + Request.RawUrl + ": " + se.Error.Message }));
            }
        }
Пример #27
0
        // GET: Department/Delete/5
        public async Task <ActionResult> Delete(string id)
        {
            EventsItem results = new EventsItem();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

            // Get the event.
            results = await eventsService.GetEvent(graphClient, id);

            if (results == null)
            {
                return(HttpNotFound());
            }
            return(View(results));
        }
Пример #28
0
        // Reply to a specified message.
        public async Task <ActionResult> ReplyToMessage(string id)
        {
            ResultsViewModel results = new ResultsViewModel(false);

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

                results.Items = await mailService.ReplyToMessage(graphClient, id);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Mail", results));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,student_id,student_Name,message,Date_Created,is_archived,Email")] StudentMessage studentMessage)
        {
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
            var userDetails = await eventsService.GetMyDetails(graphClient);

            if (ModelState.IsValid)
            {
                studentMessage.Date_Created = DateTime.Now;
                studentMessage.Email        = Session["facultyMail"].ToString();
                studentMessage.is_archived  = false;
                studentMessage.student_id   = userDetails.Mail;
                studentMessage.student_Name = userDetails.DisplayName;

                db.Entry(studentMessage).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Email = new SelectList(db.faculties, "Email", "first_Name", studentMessage.Email);
            return(View(studentMessage).Success("Message Edited."));
        }
        // GET: StudentMessages
        public async Task <ActionResult> Index()
        {
            // Initialize the GraphServiceClient.
            GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
            var userDetails = await eventsService.GetMyDetails(graphClient);

            if (Session["facultyMail"] != null)
            {
                List <StudentMessage> studentMessages = new List <StudentMessage>();
                var messages = db.messages.ToList();
                foreach (var msg in messages)
                {
                    if (msg.student_id.Equals(userDetails.Mail))
                    {
                        studentMessages.Add(msg);
                    }
                }
                return(View(studentMessages));
            }
            return(RedirectToAction("Home", "Home").Information("Please Select the faculty"));
        }