public async Task <UserNotificationModel> GetByUser(string userId, byte pageIndex = 0, byte numberInPage = 0, byte numTop = 0)
        {
            try
            {
                var list = new List <string> {
                    "Id", "UserId", "NumTop", "pageIndex", "numberInPage"
                };
                var para = APIProvider.APIDefaultParameter(list, "", userId, numTop, pageIndex, numberInPage);

                var source = await _userNotificationRepo.QueryPaging(para);

                var dest = Mapper.Map <List <UserNotificationViewModel> >(source.Item1);

                dest = dest == null ? new List <UserNotificationViewModel>() : dest;

                var result = new UserNotificationModel();
                result.lstUserNotificationViewModel = dest;
                result.TotalItem = source.Item2;

                return(result);
            }
            catch (Exception ex)
            {
                throw ex.GetBaseException();
            }
        }
Ejemplo n.º 2
0
        public async Task SetUserNotificationDismissed(UserNotificationModel userNotificationModel, string authenticationToken)
        {
            try
            {
                NotificationService notificationService = new NotificationService();

                var response = await notificationService.SetUserNotificationDismissed(userNotificationModel, authenticationToken);

                if (!response.IsSuccessStatusCode)
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        throw new Exception("Unauthorized");
                    }
                    else
                    {
                        throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public JsonResult GetData(int pageIndex, int numberInPage)
        {
            string apiNotificationUrl = APIProvider.APIGenerator("UserNotification", new List <string> {
                "userId", "NumTop", "pageIndex", "numberInPage"
            }, true, _userSession.UserId, 0, pageIndex, numberInPage);

            var data = APIProvider.Authorize_GetNonAsync <UserNotificationModel>(_userSession.BearerToken, apiNotificationUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

            if (data == null)
            {
                data           = new UserNotificationModel();
                data.TotalItem = 0;
                data.lstUserNotificationViewModel = new List <UserNotificationViewModel>();
            }

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        private void openNotification(UserNotificationModel userNotificationModel)
        {
            if (UserNotificationType.FriendAccepted.ToString().Equals(userNotificationModel.type) || UserNotificationType.FriendRequest.ToString().Equals(userNotificationModel.type) ||
                UserNotificationType.GroupMemberRequest.ToString().Equals(userNotificationModel.type))
            {
                Utils.OpenUserProfile(this.NavigationController, userNotificationModel.notificationUser.id);
            }
            else if (UserNotificationType.SurveyComment.ToString().Equals(userNotificationModel.type) || UserNotificationType.SurveyTagged.ToString().Equals(userNotificationModel.type))
            {
                var commentController = this.Storyboard.InstantiateViewController("CommentViewController") as CommentViewController;
                var feedController    = this.Storyboard.InstantiateViewController("FeedController") as FeedController;

                var notificationParams = userNotificationModel.link.Split(';');

                commentController.feedController = feedController;
                commentController.userId         = notificationParams[0].ToString().Substring(0, 36);
                commentController.creationDate   = notificationParams[0].ToString().Substring(36, 15);

                if (notificationParams.Count() > 1)
                {
                    commentController.commentDate = notificationParams[1].ToString();
                }

                this.NavigationController.PushViewController(commentController, true);
            }
            else if (UserNotificationType.SurveyVote.ToString().Equals(userNotificationModel.type))
            {
                var resultController = this.Storyboard.InstantiateViewController("ResultViewController") as ResultViewController;
                var feedController   = this.Storyboard.InstantiateViewController("FeedController") as FeedController;

                resultController.feedController = feedController;
                resultController.userId         = userNotificationModel.link.ToString().Substring(0, 36);
                resultController.creationDate   = userNotificationModel.link.ToString().Substring(36, 15);
                resultController.indexPathRow   = 0;

                this.NavigationController.PushViewController(resultController, true);
            }
            else if (UserNotificationType.GroupMemberAccepted.ToString().Equals(userNotificationModel.type))
            {
                Utils.OpenGroupProfile(this.NavigationController, userNotificationModel.notificationUser.id);
            }
        }
Ejemplo n.º 6
0
        public async Task <HttpResponseMessage> SetUserNotificationDismissed(UserNotificationModel userNotificationModel, string authenticationToken)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var formContent = new StringContent(JsonConvert.SerializeObject(userNotificationModel, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }), Encoding.UTF8, "application/json");

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

                    return(await client.PostAsync(EnvironmentConstants.getServerUrl() + "api/survey/setusernotificationdismissed", formContent));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <UserNotificationModel> > GetAllNotification()
        {
            return(await Task.Run(() =>
            {
                var notificationList = new List <UserNotificationModel>();
                var data = _contex.Notifications;
                if (data != null)
                {
                    foreach (var item in data)
                    {
                        var model = new UserNotificationModel();
                        model.NotificationId = item.Id;
                        model.UserId = item.UserId;
                        model.Name = item.User.First_Name;
                        model.Comment = item.Comment;
                        model.IsRead = item.IsRead;
                        notificationList.Add(model);
                    }
                }

                return notificationList;
            }));
        }
Ejemplo n.º 8
0
 private async void setNotificationDismissed(UserNotificationModel userNotificationModel)
 {
     await new NotificationManager().SetUserNotificationDismissed(userNotificationModel, LoginController.tokenModel.access_token);
 }