Example #1
0
        public UserNotification CommentNotification(PictureComments comments)
        {
            string           id       = _session.GetString("UserId");
            int              currUser = Convert.ToInt32(id);
            var              _File    = _context.ProfilesPictureGalleries.Where(a => a.Id == comments.PictureId).FirstOrDefault();
            var              _notify  = _context.UserNotifications.Where(a => a.PictureId == comments.PictureId && a.FriendId == currUser && a.CommentedId == comments.Id && a.Type == NotificationTypes.Commented).FirstOrDefault();
            UserNotification notif    = new UserNotification();

            if (_notify == null)
            {
                notif.CommentedId = comments.Id;
                notif.UserId      = _File.UserId;
                notif.FriendId    = currUser;
                notif.Type        = NotificationTypes.Commented;
                notif.PictureId   = _File.Id;
                notif.IsRead      = false;
                notif.DateCreated = DateTime.Now;
                _context.UserNotifications.Add(notif);
            }
            else
            {
                notif = _notify;
                notif.DateModified = DateTime.Now;
                notif.IsRead       = false;
                notif.Type         = NotificationTypes.Commented;
                notif.DateDeleted  = null;
                _context.UserNotifications.Update(notif);
            }
            _accountRepository.Save();
            return(notif);
        }
Example #2
0
 public PictureComments SentComment(PictureComments comments)
 {
     try
     {
         var _comment = new PictureComments();
         if (comments.Id != 0)
         {
             _comment              = _context.PictureComments.Where(a => a.Id == comments.Id).FirstOrDefault();
             _comment.Message      = comments.Message;
             _comment.DateModified = DateTime.Now;
             _comment.DateDeleted  = null;
             _context.PictureComments.Update(_comment);
         }
         else
         {
             string UserId = _session.GetString("UserId");
             _comment.Message     = comments.Message;
             _comment.UserId      = int.Parse(UserId);
             _comment.PictureId   = comments.PictureId;
             _comment.DateCreated = DateTime.Now;
             _context.PictureComments.Add(_comment);
         }
         _accountRepository.Save();
         return(_comment);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #3
0
        public UserNotification UpdateNotification(PictureComments comments)
        {
            var _notification = _context.UserNotifications.Where(a => a.CommentedId == comments.Id).FirstOrDefault();

            _notification.DateDeleted = DateTime.Now;
            _notification.IsRead      = false;
            _context.UserNotifications.Update(_notification);
            _accountRepository.Save();
            return(_notification);
        }
Example #4
0
        public JsonResult SendComment(PictureComments comments)
        {
            var data         = _commentRepository.SentComment(comments);
            var notification = _commentRepository.CommentNotification(data);

            if (notification != null)
            {
                _notificationHub.SendNotification(notification);
            }
            return(Json(data));
        }
Example #5
0
        public PictureComments DeleteComments(int commentid)
        {
            try
            {
                PictureComments pictureComments = _context.PictureComments.Where(a => a.Id == commentid).FirstOrDefault();
                pictureComments.DateDeleted = DateTime.Now;
                _context.PictureComments.Update(pictureComments);

                //Delete Comment Replay
                var pictureCommentReplay = _context.PictureCommentReplays.Where(a => a.PictureCommentId == commentid).ToList();

                foreach (var item in pictureCommentReplay)
                {
                    item.DateDeleted = DateTime.Now;
                    _context.PictureCommentReplays.Update(item);
                }
                _accountRepository.Save();
                return(pictureComments);
            }
            catch (Exception)
            {
                throw;
            }
        }