public async Task <ActionResult <PostDownloadDTO> > PostPost(PostUploadDTO postUploadDTO, Guid parentId)
        {
            // If parentId does not exist, return from method.
            var parentPost = await _context.Posts.FindAsync(parentId);

            if (parentPost == null)
            {
                return(NotFound());
            }

            // Get user based on existing JWT Token or Guest User account.
            var user = await GetUserFromTokenOrDefault();

            // Return Unauthorized if no AppUser account could be assigned.
            if (user == null)
            {
                return(Unauthorized("Account could not be located."));
            }

            Post post = _mapper.Map <PostUploadDTO, Post>(postUploadDTO);

            post.ParentId  = parentId;
            post.AppUserId = user.Id;

            user.Posts.Add(post);
            parentPost.Children.Add(post);
            _context.Posts.Add(post);
            await _context.SaveChangesAsync();

            var postDownloadDTO = _mapper.Map <Post, PostDownloadDTO>(post);

            return(CreatedAtAction("GetPost", new { id = post.Id }, postDownloadDTO));
        }
        private string GetJsonTextForNewDeviceDataForPostUpload()
        {
            /** BEGIN: Snippet to Update RAW Json Request with Base 64 String that was set from file **/
            APIBuiltInTestCase selectedBuiltInTest = (
                from i in BuiltInTestCaseRepo.Instance.AllTestCases
                where i.Name.Equals(cBBuiltInTests.Text)
                select i).FirstOrDefault();

            if (chkBxUseFile.Checked && selectedBuiltInTest != null &&
                selectedBuiltInTest.GetType().Equals(typeof(PostUploadTest)) &&
                !string.IsNullOrEmpty(base64String))
            {
                try
                {
                    PostUploadDTO postUploadDTO = Newtonsoft.Json.JsonConvert.DeserializeObject <PostUploadDTO>(new Regex("(\r\n|\r|\n)").Replace(txtBxRequest.Text, ""));
                    postUploadDTO.ActivityFiles.FirstOrDefault().DeviceData = base64String;

                    JsonSerializerSettings jsonFormatter = new JsonSerializerSettings
                    {
                        Formatting           = Newtonsoft.Json.Formatting.Indented,
                        DateFormatHandling   = DateFormatHandling.IsoDateFormat,
                        DateTimeZoneHandling = DateTimeZoneHandling.Utc
                    };
                    return(JsonConvert.SerializeObject(postUploadDTO, jsonFormatter));
                }
                catch { }
            }
            /** END: Snippet to Update Json Request with Base 64 String **/
            return(null);
        }
        /// <summary>
        /// Updated 'Device Data' field in request text box
        /// </summary>
        /// <param name="value"></param>
        private void UpdateDeviceDataInRequestTextBoxForPostUpload(string value)
        {
            APIBuiltInTestCase apiTest = (
                from i in BuiltInTestCaseRepo.Instance.AllTestCases
                where i.Name.Equals(cBBuiltInTests.Text)
                select i).FirstOrDefault();

            if (apiTest.GetType().Equals(typeof(PostUploadTest)))
            {
                PostUploadDTO postUploadDTO = Newtonsoft.Json.JsonConvert.DeserializeObject <PostUploadDTO>(new Regex("(\r\n|\r|\n)").Replace(txtBxRequest.Text, ""));
                postUploadDTO.ActivityFiles.FirstOrDefault().DeviceData = value;

                JsonSerializerSettings jsonFormatter = new JsonSerializerSettings {
                    Formatting           = Newtonsoft.Json.Formatting.Indented,
                    DateFormatHandling   = DateFormatHandling.IsoDateFormat,
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                };
                txtBxRequest.Text = JsonConvert.SerializeObject(postUploadDTO, jsonFormatter);
            }
        }
        public void SetDeviceData(string deviceDataBase64String)
        {
            PostUploadDTO postUploadDTO = ((PostUploadDTO)this.dto);

            postUploadDTO.ActivityFiles.FirstOrDefault().DeviceData = deviceDataBase64String;
        }
        public void SetFileType(string fileType)
        {
            PostUploadDTO postUploadDTO = ((PostUploadDTO)this.dto);

            postUploadDTO.ActivityFiles.FirstOrDefault().FileType = fileType;
        }