Exemplo n.º 1
0
        private void CommentButton_TouchUpInside(object sender, EventArgs e)
        {
            SurveyCommentModel surveyCommentModel = new SurveyCommentModel();

            surveyCommentModel.text           = commentArea.CommentText.Text;
            surveyCommentModel.surveyId       = survey.userId + survey.creationDate;
            surveyCommentModel.profilePicture = LoginController.userModel.profilePicturePath;
            surveyCommentModel.userId         = LoginController.userModel.id;
            surveyCommentModel.userName       = LoginController.userModel.name;
            surveyCommentModel.commentDate    = EnvironmentConstants.getServerDateTime().ToString("yyyyMMddTHHmmssfff");



            comments.Add(surveyCommentModel);
            var indexes = new NSIndexPath[] { NSIndexPath.FromItemSection(comments.IndexOf(comments.Last()), 0) };

            createComment(surveyCommentModel, indexes);

            feed.InsertItems(indexes);
            feed.ScrollToItem(indexes.First(), UICollectionViewScrollPosition.Bottom, true);

            commentArea.CommentText.Text      = null;
            commentArea.CommentButton.Enabled = false;
            View.EndEditing(true);
            ScrollTheView(false);
        }
Exemplo n.º 2
0
        private async void createComment(SurveyCommentModel surveyCommentModel, NSIndexPath[] indexes)
        {
            try
            {
                survey.totalComments += 1;
                feedCell.updateTotalComments(survey.totalComments);

                surveyCommentModel.commentDate = (await new CommentManager().CreateSurveyComment(surveyCommentModel, LoginController.tokenModel.access_token)).commentDate;

                try
                {
                    if (LoginController.userModel.id != survey.userId)
                    {
                        UserNotificationModel userNotificationModel = new UserNotificationModel();
                        userNotificationModel.notificationDate = "";
                        userNotificationModel.userId           = survey.userId;
                        userNotificationModel.notificationUser = new UserFriendModel(LoginController.userModel.id, LoginController.userModel.name, LoginController.userModel.profilePicturePath);
                        userNotificationModel.type             = UserNotificationType.SurveyComment.ToString();

                        if (survey.question.text.Length > 25)
                        {
                            userNotificationModel.text = "commented on \"" + survey.question.text.Substring(0, 25) + "...\"";
                        }
                        else
                        {
                            userNotificationModel.text = "commented on \"" + survey.question.text + "\"";
                        }

                        userNotificationModel.link        = surveyCommentModel.surveyId + ";" + surveyCommentModel.commentDate;
                        userNotificationModel.isDismissed = 0;
                        userNotificationModel.isRead      = 0;

                        await new NotificationManager().SetUserNotification(userNotificationModel, LoginController.tokenModel.access_token);
                    }
                }
                catch
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                survey.totalComments -= 1;
                feedCell.updateTotalComments(survey.totalComments);

                comments.RemoveAt(indexes.First().Row);
                feed.DeleteItems(indexes);

                Utils.HandleException(ex);
            }
        }
Exemplo n.º 3
0
        public async Task DeleteSurveyComment(SurveyCommentModel surveyCommentModel, string authenticationToken)
        {
            try
            {
                CommentService commentService = new CommentService();

                var response = await commentService.DeleteSurveyComment(surveyCommentModel, authenticationToken);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 4
0
        public async Task <HttpResponseMessage> DeleteSurveyComment(SurveyCommentModel surveyCommentModel, string authenticationToken)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var formContent = new StringContent(JsonConvert.SerializeObject(surveyCommentModel, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }), Encoding.UTF8, "application/json");

                    client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + authenticationToken);

                    return(await client.PostAsync(EnvironmentConstants.getServerUrl() + "api/survey/deletesurveycomment", formContent));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 5
0
        private void HandleLongPressSelector(UICommentLongPressGestureRecognizer gestureRecognizer)
        {
            if (gestureRecognizer.State == UIGestureRecognizerState.Began)
            {
                View.EndEditing(true);
                this.comment = (SurveyCommentModel)gestureRecognizer.Params.ToArray()[0];

                commentAction = UIAlertController.Create("Comment Menu", "Select your action", UIAlertControllerStyle.ActionSheet);
                if (commentAction.Actions.Count() <= 0)
                {
                    if (!this.comment.userId.Equals(LoginController.userModel.id))// not comment owner
                    {
                        commentAction.AddAction(UIAlertAction.Create("Report Comment", UIAlertActionStyle.Destructive, alert => ReportComment()));
                        commentAction.AddAction(UIAlertAction.Create("Report Comment User", UIAlertActionStyle.Destructive, alert => ReportCommentUser()));
                    }
                    else
                    {
                        commentAction.AddAction(UIAlertAction.Create("Delete Comment", UIAlertActionStyle.Destructive, alert => DeleteCommentSelector()));
                    }

                    commentAction.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
                }

                var mainWindow     = UIApplication.SharedApplication.KeyWindow;
                var viewController = mainWindow?.RootViewController;
                while (viewController?.PresentedViewController != null)
                {
                    viewController = viewController.PresentedViewController;
                }
                if (viewController == null)
                {
                    viewController = this;
                }

                viewController.PresentViewController(commentAction, true, null);
            }
        }
Exemplo n.º 6
0
        public async Task <SurveyCommentModel> CreateSurveyComment(SurveyCommentModel surveyCommentModel, string authenticationToken)
        {
            try
            {
                CommentService commentService = new CommentService();

                var response = await commentService.CreateSurveyComment(surveyCommentModel, authenticationToken);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <SurveyCommentModel>(json));
                }
                else
                {
                    throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }