Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                /* Save the Context Token and Host Web URL in hidden fields
                 * These will be needed to create client contexts in subsequent calls */
                hdnContextToken.Value = TokenHelper.GetContextTokenFromRequest(Page.Request);
                hdnHostWeb.Value      = Page.Request["SPHostUrl"];

                List <AssignmentPost> posts = new List <AssignmentPost>();

                /* Create a collection of posts that mention the current user
                 * and are tagged with #Assignment. These posts are candidates
                 * to be turned into tasks for the current user */

                using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority))
                {
                    try
                    {
                        //Get current user
                        ctx.Load(ctx.Web, w => w.CurrentUser);
                        ctx.ExecuteQuery();

                        //Get posts that mention the current user
                        SocialFeedManager feedManager = new SocialFeedManager(ctx);
                        ctx.Load(feedManager);

                        SocialFeedOptions feedOptions = new SocialFeedOptions();
                        feedOptions.MaxThreadCount = 50;
                        feedOptions.SortOrder      = SocialFeedSortOrder.ByCreatedTime;
                        ClientResult <SocialFeed> feedData = feedManager.GetMentions(false, feedOptions);
                        ctx.ExecuteQuery();

                        //Build a collection of posts tagged with #Assignment
                        foreach (SocialThread thread in feedData.Value.Threads)
                        {
                            if (thread.PostReference.Post.Text.Contains("#Assignment"))
                            {
                                AssignmentPost post = new AssignmentPost();
                                post.CreatedDate = thread.RootPost.CreatedTime;
                                post.Body        = thread.PostReference.Post.Text
                                                   .Replace("#Assignment", string.Empty)
                                                   .Replace("@" + ctx.Web.CurrentUser.Title, string.Empty);
                                post.Requester = thread.Actors[thread.PostReference.Post.AuthorIndex].Name;
                                posts.Add(post);
                            }
                        }

                        //Bind these posts for display
                        assignmentPosts.DataSource = posts;
                        assignmentPosts.DataBind();
                    }
                    catch (Exception x)
                    {
                        messages.Text = x.Message;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] AssignmentPost assignment)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var newAssignment = new Assignment
                    {
                        EmployeeId  = assignment.EmployeeId,
                        ProjectId   = assignment.ProjectId,
                        Location    = assignment.Location,
                        Commitments = assignment.Commitments
                    };

                    var addedAssignment = await _repo.Create(newAssignment);

                    if (assignment.newJobTitles != null)
                    {
                        foreach (var newJobTitle in assignment.newJobTitles)
                        {
                            var AddedJobTitle = await _repoJob.Create(new JobTitle
                            {
                                TitleName = newJobTitle
                            });

                            var addedJobTitleAssignment = await _repoJobA.Create(new JobTitleAssignment
                            {
                                AssignmentId = addedAssignment.AssignmentId,
                                JobTitleId   = AddedJobTitle.JobTitleId
                            });
                        }
                    }

                    if (assignment.jobTitles != null)
                    {
                        foreach (var jobTitle in assignment.jobTitles)
                        {
                            var addedJobTitleAssignment = await _repoJobA.Create(new JobTitleAssignment
                            {
                                AssignmentId = addedAssignment.AssignmentId,
                                JobTitleId   = jobTitle.JobTitleId
                            });
                        }
                    }

                    return(Ok(addedAssignment));
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Exception thrown while posting assignment: {ex.Message}");
                    return(BadRequest($"Error ocurred"));
                }
            }
            return(BadRequest("Failed to save changes to the database"));
        }
        private List <AssignmentPost> GetAssignmentCandidates()
        {
            try
            {
                /* Get all posts where the current user is mentioned
                 * and are tagged with #Assignment. These are candidates
                 * to become tasks for the current user */

                List <AssignmentPost> posts = new List <AssignmentPost>();

                //Make the request
                string    endpoint    = hdnHostWeb.Value + "/_api/social.feed/my/MentionFeed";
                XDocument responseDoc = GetDataREST(endpoint);

                //Parse the response
                XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";

                var assignments = from e in responseDoc.Root.Descendants(d + "Threads").First().Elements(d + "element")
                                  select new
                {
                    Body        = e.Element(d + "PostReference").Element(d + "Post").Element(d + "Text").Value,
                    CreatedDate = DateTime.Parse(e.Element(d + "RootPost").Element(d + "CreatedTime").Value),
                    Requester   = e.Element(d + "Actors").Elements(d + "element").ElementAt(int.Parse(e.Element(d + "PostReference").Element(d + "Post").Element(d + "AuthorIndex").Value)).Element(d + "Name").Value
                };


                //Build a collection of assignment candidates
                foreach (var assignment in assignments)
                {
                    if (assignment.Body.Contains("#Assignment"))
                    {
                        AssignmentPost post = new AssignmentPost();
                        post.CreatedDate = assignment.CreatedDate;
                        post.Body        = assignment.Body
                                           .Replace("#Assignment", string.Empty)
                                           .Replace("@" + hdnDisplayName.Value, string.Empty);
                        post.Requester = assignment.Requester;
                        posts.Add(post);
                    }
                }

                return(posts);
            }
            catch (Exception x)
            {
                messages.Text = x.Message;
                return(new List <AssignmentPost>());
            }
        }
        private List<AssignmentPost> GetAssignmentCandidates()
        {
            try
            {
                /* Get all posts where the current user is mentioned
                 * and are tagged with #Assignment. These are candidates
                 * to become tasks for the current user */

                List<AssignmentPost> posts = new List<AssignmentPost>();

                //Make the request
                string endpoint = hdnHostWeb.Value + "/_api/social.feed/my/MentionFeed";
                XDocument responseDoc = GetDataREST(endpoint);

                //Parse the response
                XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";

                var assignments = from e in responseDoc.Root.Descendants(d + "Threads").First().Elements(d + "element")
                                  select new
                                  {
                                      Body = e.Element(d + "PostReference").Element(d + "Post").Element(d + "Text").Value,
                                      CreatedDate = DateTime.Parse(e.Element(d + "RootPost").Element(d + "CreatedTime").Value),
                                      Requester = e.Element(d + "Actors").Elements(d + "element").ElementAt(int.Parse(e.Element(d + "PostReference").Element(d + "Post").Element(d + "AuthorIndex").Value)).Element(d + "Name").Value
                                  };

                //Build a collection of assignment candidates
                foreach (var assignment in assignments)
                {
                    if (assignment.Body.Contains("#Assignment"))
                    {
                        AssignmentPost post = new AssignmentPost();
                        post.CreatedDate = assignment.CreatedDate;
                        post.Body = assignment.Body
                            .Replace("#Assignment", string.Empty)
                            .Replace("@" + hdnDisplayName.Value,string.Empty);
                        post.Requester = assignment.Requester;
                        posts.Add(post);
                    }
                }

                return posts;

            }
            catch (Exception x)
            {
                messages.Text = x.Message;
                return new List<AssignmentPost>();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                /* Save the Context Token and Host Web URL in hidden fields
                 * These will be needed to create client contexts in subsequent calls */
                hdnContextToken.Value = TokenHelper.GetContextTokenFromRequest(Page.Request);
                hdnHostWeb.Value = Page.Request["SPHostUrl"];

                List<AssignmentPost> posts = new List<AssignmentPost>();

                /* Create a collection of posts that mention the current user
                 * and are tagged with #Assignment. These posts are candidates
                 * to be turned into tasks for the current user */

                using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority))
                {
                    try
                    {
                        //Get current user
                        ctx.Load(ctx.Web, w => w.CurrentUser);
                        ctx.ExecuteQuery();

                        //Get posts that mention the current user
                        SocialFeedManager feedManager = new SocialFeedManager(ctx);
                        ctx.Load(feedManager);

                        SocialFeedOptions feedOptions = new SocialFeedOptions();
                        feedOptions.MaxThreadCount = 50;
                        feedOptions.SortOrder = SocialFeedSortOrder.ByCreatedTime;
                        ClientResult<SocialFeed> feedData = feedManager.GetMentions(false, feedOptions);
                        ctx.ExecuteQuery();

                        //Build a collection of posts tagged with #Assignment
                        foreach (SocialThread thread in feedData.Value.Threads)
                        {
                            if (thread.PostReference.Post.Text.Contains("#Assignment"))
                            {
                                AssignmentPost post = new AssignmentPost();
                                post.CreatedDate = thread.RootPost.CreatedTime;
                                post.Body = thread.PostReference.Post.Text
                                    .Replace("#Assignment", string.Empty)
                                    .Replace("@" + ctx.Web.CurrentUser.Title, string.Empty);
                                post.Requester = thread.Actors[thread.PostReference.Post.AuthorIndex].Name;
                                posts.Add(post);
                            }
                        }

                        //Bind these posts for display
                        assignmentPosts.DataSource = posts;
                        assignmentPosts.DataBind();
                    }
                    catch (Exception x)
                    {
                        messages.Text = x.Message;
                    }
                }
            }
        }