public async void SetMedia(string mediaId)
        {
            var media = await Helper.InstaApi.MediaProcessor.GetMediaByIdAsync(mediaId);

            if (media.Succeeded)
            {
                Media = media.Value;
                if (ScrollView == null)
                {
                    //if (NavigationMode == NavigationMode.Back) return;
                    ScrollView = ItemsLV.FindScrollViewer();
                    if (ScrollView != null)
                    {
                        ScrollView.ViewChanging += ScrollViewViewChanging;
                    }
                    CommentsVM.SetLV(ScrollView);
                }
                CommentsVM.ResetCache();
                ToggleGoUpButtonAnimation(false);
                if (Media != null)
                {
                    CommentsVM.SetMedia(Media);
                }
                CommentsVM.RunLoadMore(true);
            }
        }
        public ActionResult AddComment(CommentsVM comment, int postId)
        {
            var userId = User.Identity.GetUserId();
            //bool result = false;

            var Comments = new Comments();

            var user = dbContext.Users.FirstOrDefault(u => u.Id == userId);
            var post = dbContext.Posts.FirstOrDefault(p => p.Id == postId);

            if (comment != null)
            {
                Comments.CommentMsg = comment.CommentMsg;

                Comments.CommentedDate = comment.CommentedDate;

                if (user != null && post != null)
                {
                    post.Comment.Add(Comments);
                    user.Comments.Add(Comments);

                    dbContext.SaveChanges();
                    //result = true;
                }
                //Once the record is inserted , then notify all the subscribers (Clients)
                CommentsHub.NotifyCurrentUserInformationToAllClients();
            }

            return(RedirectToAction("GetComments", "Comments", new { postId = postId }));
        }
        public ActionResult RequestSpecificIndex(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var commentses = db.Commentses.Include(c => c.Request).Where(e => e.RequestId == id);
            List <CommentsVM> commentsList = new List <CommentsVM>();

            foreach (var item in commentses)
            {
                var        userId     = item.UserId;
                CommentsVM commentsVm = new CommentsVM();
                commentsVm.UserId      = userId;
                commentsVm.Description = item.Description;
                commentsVm.DateTime    = item.DateTime;
                commentsVm.RequestId   = item.RequestId;
                var commentsBy = db.Employees.Include(e => e.Department).Include(e => e.Designation).FirstOrDefault(e => e.UserId == userId);

                if (commentsBy != null)
                {
                    commentsVm.EmpIdNo         = commentsBy.EmpIdNo;
                    commentsVm.Name            = commentsBy.Name;
                    commentsVm.DepartmentName  = commentsBy.Department.Name;
                    commentsVm.DesignationName = commentsBy.Designation.Name;
                }
                //db.Employees.Where(e => e.UserId == item.UserId).Select(e => e.EmpIdNo).FirstOrDefault();

                commentsList.Add(commentsVm);
            }
            ViewBag.UserId    = ApplicationUser().Id;
            ViewBag.RequestId = id;
            return(View(commentsList));
        }
Beispiel #4
0
        public ActionResult AddComment(CommentsVM comment, int postId)
        {
            //bool result = false;
            Comment commentEntity = null;
            string  uname         = User.Identity.Name;
            var     obj           = db.Logins.Where(x => x.Username.Equals(uname)).FirstOrDefault();
            int     userId        = obj.id;

            var user = db.Logins.FirstOrDefault(u => u.id == userId);
            var post = db.Songs.FirstOrDefault(p => p.id == postId);

            if (comment != null)
            {
                commentEntity = new Comment
                {
                    Msg  = comment.CommentMsg,
                    Date = comment.CommentedDate,
                };


                if (user != null && post != null)
                {
                    post.Comments.Add(commentEntity);
                    user.Comments.Add(commentEntity);

                    db.SaveChanges();
                }
            }

            return(RedirectToAction("GetComments", "Songs", new { postId = postId }));
        }
        /// <summary>
        /// Comments list
        /// </summary>
        /// <param name="commentType">Comment type</param>
        /// <param name="take">Items to take</param>
        /// <param name="skip">Items to skip</param>
        /// <param name="filter">Filter expression</param>
        /// <param name="order">Sort order</param>
        /// <returns>List of comments</returns>
        public CommentsVM Get()
        {
            if (!Security.IsAuthorizedTo(Rights.ViewPublicComments))
            {
                throw new UnauthorizedAccessException();
            }

            var vm       = new CommentsVM();
            var comments = new List <Comment>();
            var items    = new List <CommentItem>();

            var all = Security.IsAuthorizedTo(Rights.EditOtherUsersPosts);

            foreach (var p in Post.Posts)
            {
                if (all || p.Author.ToLower() == Security.CurrentUser.Identity.Name.ToLower())
                {
                    comments.AddRange(p.Comments);
                }
            }
            foreach (var c in comments)
            {
                items.Add(Json.GetComment(c, comments));
            }
            vm.Items = items;

            vm.Detail       = new CommentDetail();
            vm.SelectedItem = new CommentItem();

            return(vm);
        }
Beispiel #6
0
        public ActionResult AddComment(CommentsVM comment, int postId)
        {
            //bool result = false;
            Comment commentEntity = null;
            int     userId        = (int)Session["UserID"];

            var user = dbContext.Users.FirstOrDefault(u => u.UserID == userId);
            var post = dbContext.Posts.FirstOrDefault(p => p.PostID == postId);

            if (comment != null)
            {
                commentEntity = new EDMX.Comment
                {
                    CommentMsg    = comment.CommentMsg,
                    CommentedDate = comment.CommentedDate,
                };


                if (user != null && post != null)
                {
                    post.Comments.Add(commentEntity);
                    user.Comments.Add(commentEntity);

                    dbContext.SaveChanges();
                    //result = true;
                }
            }

            return(RedirectToAction("GetComments", "Comments", new { postId = postId }));
        }
Beispiel #7
0
        public ActionResult NewComment(PhotoVM photo)
        {
            var newComment = new CommentsVM();

            newComment.PhotoID = photo.id;

            return(View(newComment));
        }
Beispiel #8
0
        public static CommentsDTO ToDTO(this CommentsVM vm)
        {
            CommentsDTO dto = new CommentsDTO();

            dto.CommentDate = vm.CommentDate;
            dto.CommentMsg  = vm.CommentMsg;
            dto.UserId      = vm.UserId;
            return(dto);
        }
Beispiel #9
0
        public static CommentsVM ToViewModel(this CommentsDTO dto)
        {
            CommentsVM vm = new CommentsVM();

            vm.ComId       = dto.ComId;
            vm.CommentDate = dto.CommentDate;
            vm.CommentMsg  = dto.CommentMsg;
            vm.UserId      = dto.UserId;
            return(vm);
        }
Beispiel #10
0
        public void SaveComment(CommentsVM commentVM)
        {
            Comment comment = new Comment();

            comment.CommentBy = commentVM.CommentBy;
            comment.PostID    = commentVM.PostID;
            comment.Text      = commentVM.Text;

            commentRepository.SavePostComment(comment);
        }
 private void OnKeyDownHandler(object sender, KeyRoutedEventArgs e)
 {
     try
     {
         if (e.Key == Windows.System.VirtualKey.F5)
         {
             CommentsVM.RunLoadMore(true);
         }
     }
     catch { }
 }
        public CommentsVM Get()
        {
            var vm = new CommentsVM();

            vm.Items = new List <CommentItem>();
            vm.Items.Add(new CommentItem()
            {
                Id = Guid.NewGuid()
            });
            return(vm);
        }
 private void MoreTailChildCommentsButtonClick(object sender, RoutedEventArgs e)
 {
     // max id mikhad, yani insert(0, item) bayad bezani
     try
     {
         if (sender is HyperlinkButton hyper && hyper.DataContext is InstaComment comment)
         {
             CommentsVM.GetTailCommentReplies(comment);
         }
     }
     catch { }
 }
 private void MoreHeadChildCommentsButtonClick(object sender, RoutedEventArgs e)
 {
     // min id mikhad, yani Add() bayad bezani
     try
     {
         if (sender is HyperlinkButton hyper && hyper.DataContext is InstaComment comment)
         {
             CommentsVM.GetHeadCommentReplies(comment);
         }
     }
     catch { }
 }
        public JsonResult SaveComment(CommentsVM commentVM)
        {
            var result = "success";

            new CommentBL().SaveComment(commentVM);
            new NotificationBL().SaveNotification(new NotificationViewModel()
            {
                Active        = true,
                Description   = commentVM.NotificationFromFullName + " commented on your post.",
                Link          = "",
                UserProfileID = commentVM.NotificationTo
            });
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #16
0
        public static CommentsDataModel ModelToEntity(CommentsVM model)
        {
            CommentsDataModel entity = new CommentsDataModel();

            entity.Comment = model.Comment;
            entity.Title   = model.Title;
            entity.ID      = model.id;
            entity.PhotoID = model.PhotoID;
            entity.UserID  = model.UserID;

            entity.Datecreated = model.DatePosted;
            entity.Dateupdated = model.DateEdited;

            return(entity);
        }
        public PartialViewResult AddComment(CommentsVM comment)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }

            comment.CommentMsg  = Server.HtmlEncode(comment.CommentMsg);
            comment.UserId      = Convert.ToInt32(User.Identity.GetUserId());
            comment.CommentDate = DateTime.Now;

            _commentProcess.AddComment(comment.ToDTO());

            return(PartialView("/Views/Shared/_Comment.cshtml", comment));
        }
Beispiel #18
0
 private void CommentViewLoaded(object sender, RoutedEventArgs e)
 {
     try
     {
         RefreshControl.RefreshRequested -= RefreshControlRefreshRequested;
         RefreshControl.Visualizer.RefreshStateChanged -= RefreshControlRefreshStateChanged;
     }
     catch { }
     RefreshControl.RefreshRequested += RefreshControlRefreshRequested;
     if (RefreshControl.Visualizer != null)
     {
         RefreshControl.Visualizer.RefreshStateChanged += RefreshControlRefreshStateChanged;
     }
     if (NavigationMode == NavigationMode.Back && CommentsVM.Media != null)
     {
         if (CommentsVM.Media.InstaIdentifier == Media.InstaIdentifier)
         {
             return;
         }
     }
     else if (NavigationMode == NavigationMode.New)
     {
         NavigationCacheMode = NavigationCacheMode.Enabled;
         CanLoadFirstPopUp   = false;
     }
     if (!CanLoadFirstPopUp)
     {
         if (ScrollView == null)
         {
             //if (NavigationMode == NavigationMode.Back) return;
             ScrollView = ItemsLV.FindScrollViewer();
             ScrollView.ViewChanging += ScrollViewViewChanging;
             CommentsVM.SetLV(ScrollView);
         }
         CommentsVM.ResetCache();
         ToggleGoUpButtonAnimation(false);
         if (Media != null)
         {
             CommentsVM.SetMedia(Media);
         }
         else
         {
             CommentsVM.SetMedia(MediaId);
         }
         CommentsVM.RunLoadMore(true);
         CanLoadFirstPopUp = true;
     }
 }
Beispiel #19
0
        public ActionResult NewComment(int postId)
        {
            CommentBL  commentBL = new CommentBL();
            CommentsVM comVM     = new CommentsVM();

            comVM.commentsList = commentBL.FindComments(postId);
            comVM.commentsList.Reverse();
            comVM.newComment        = new Comment();
            comVM.newComment.PostId = postId;
            if (Session["login"] != null)
            {
                comVM.newComment.userName = Session["login"].ToString();
            }

            return(PartialView(comVM));
        }
Beispiel #20
0
        public static CommentsVM EntityToModel(CommentsDataModel entity)
        {
            CommentsVM model = new CommentsVM();

            model.Comment = entity.Comment;
            model.Title   = entity.Title;
            model.id      = entity.ID;
            model.PhotoID = entity.PhotoID;
            model.Picture = EntityToModel(entity.Photo);
            model.UserID  = entity.UserID;
            model.User    = EntityToModel(entity.User);

            model.DateEdited = entity.Dateupdated;
            model.DatePosted = entity.Datecreated;



            return(model);
        }
Beispiel #21
0
        public ActionResult NewComment(CommentsVM model)
        {
            var identity = User.Identity.Name;
            int?userID   = Userrepo.GetID(identity);

            model.UserID = (int)userID;
            var photomodel = photorepo.ByID(model.PhotoID);

            model.DatePosted = DateTime.Now;


            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                var newComment = ModelMapper.ModelToEntity(model);
                repo.AddOrUpdate(newComment);

                return(RedirectToAction("Details", "Photo", photomodel));
            }
            return(RedirectToAction("Details", "Photo", photomodel));
        }
Beispiel #22
0
        public async void GetDatabase(bool updateAll = false)
        {
            await UpdateDatabase(updateAll);

            CommentsVM = commentDatabase.Get()
                         .Where(i => i.PostId == PostVM.Id)
                         .Select(i => new CommentModel
            {
                Id      = i.Id,
                Comment = i.Comment,
                Name    = i.Name,
                Email   = i.Email,
                PostId  = i.PostId
            }).ToList();

            if (CommentsVM == null || !CommentsVM.Any())
            {
                Dialog.Toast("No comments found.", new TimeSpan(5));
            }
        }
        //Add comments with comments list
        public JsonResult CreateCommentsJson(CommentsWithCreateVm model)
        {
            Comments cm = new Comments();

            cm.UserId      = ApplicationUser().Id;
            cm.Description = model.Description;
            cm.DateTime    = model.DateTime;
            cm.RequestId   = model.RequestId;
            db.Commentses.Add(cm);
            db.SaveChanges();
            var commentses = db.Commentses.Include(c => c.Request).Where(e => e.RequestId == cm.RequestId);

            model.CommentsVms = new List <CommentsVM>();

            foreach (var item in commentses)
            {
                var        userId     = item.UserId;
                CommentsVM commentsVm = new CommentsVM();
                commentsVm.UserId      = userId;
                commentsVm.Description = item.Description;
                commentsVm.DateTime    = item.DateTime;
                commentsVm.RequestId   = item.RequestId;
                var commentsBy = db.Employees.Include(e => e.Department).Include(e => e.Designation).FirstOrDefault(e => e.UserId == userId);

                if (commentsBy != null)
                {
                    commentsVm.EmpIdNo         = commentsBy.EmpIdNo;
                    commentsVm.Name            = commentsBy.Name;
                    commentsVm.DepartmentName  = commentsBy.Department.Name;
                    commentsVm.DesignationName = commentsBy.Designation.Name;
                }
                //db.Employees.Where(e => e.UserId == item.UserId).Select(e => e.EmpIdNo).FirstOrDefault();

                model.CommentsVms.Add(commentsVm);
            }
            //ViewBag.UserId = ApplicationUser().Id;
            //ViewBag.RequestId = id;
            // return View(model);

            return(Json(model.CommentsVms, JsonRequestBehavior.AllowGet));
        }
Beispiel #24
0
        public ActionResult CommentList(CommentsVM comVM)
        {
            comVM.newComment.date = DateTime.Now;

            CommentBL commentBL = new CommentBL();

            commentBL.AddComment(comVM.newComment);
            int postId = comVM.newComment.PostId;

            comVM.commentsList = commentBL.FindComments(postId);
            comVM.commentsList.Reverse();

            PostBL      postBL = new PostBL();
            List <Post> list   = postBL.GetPosts();
            Post        post   = list.Where(u => u.PostId == postId).Single();

            post.numOfComments += 1;
            postBL.EditPost(post);

            return(PartialView("CommentList", comVM));
        }
        public HttpResponseMessage Post([FromBody] commentModel model)
        {
            try
            {
                var    identity = (ClaimsIdentity)User.Identity;
                var    claims   = identity.Claims.Select(x => new { type = x.Type, value = x.Value });
                string userId   = claims.Where(a => a.type == "UserId").Select(a => a.value).SingleOrDefault().ToString();;
                model.userId = string.IsNullOrEmpty(userId) ? 0 : Convert.ToInt32(userId);
                CommentsVM returnmodel = IService.PostComments(model);
                return(Request.CreateResponse(HttpStatusCode.OK, returnmodel));
            }
            catch (Exception ex)
            {
                ResponseObject response = new ResponseObject();
                response.ExceptionMsg = ex.InnerException != null?ex.InnerException.ToString() : ex.Message;

                response.ResponseMsg = "Could not post the comments";
                response.ErrorCode   = HttpStatusCode.InternalServerError.ToString();
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
Beispiel #26
0
        public async Task <Comments> AddComment(CommentsVM model)
        {
            try
            {
                Comments _comment = new Comments()
                {
                    CreatedDate       = DateTime.Now,
                    CreatedBy         = 1,
                    Subject           = model.Subject,
                    ResponsiblePerson = model.ResponsiblePerson,
                    Completed         = model.Completed
                };
                await _context.Comments.InsertOneAsync(_comment);

                return(_comment);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #27
0
        public ActionResult DeleteComment(int id)
        {
            CommentBL commentBL = new CommentBL();
            Comment   c         = commentBL.GetComments().Where(u => u.CommentId == id).Single();

            commentBL.DeleteComment(c);
            int postId = c.PostId;

            PostBL      postBL = new PostBL();
            List <Post> list   = postBL.GetPosts();
            Post        post   = list.Where(u => u.PostId == postId).Single();

            post.numOfComments -= 1;
            postBL.EditPost(post);

            CommentsVM comVM = new CommentsVM();

            comVM.commentsList = commentBL.FindComments(postId);
            comVM.commentsList.Reverse();

            return(PartialView("CommentList", comVM));
        }
        public void SetMedia(InstaMedia media)
        {
            Media = media;

            if (ScrollView == null)
            {
                //if (NavigationMode == NavigationMode.Back) return;
                ScrollView = ItemsLV.FindScrollViewer();
                if (ScrollView != null)
                {
                    ScrollView.ViewChanging += ScrollViewViewChanging;
                }
                CommentsVM.SetLV(ScrollView);
            }
            CommentsVM.ResetCache();
            ToggleGoUpButtonAnimation(false);
            if (Media != null)
            {
                CommentsVM.SetMedia(Media);
            }
            CommentsVM.RunLoadMore(true);
        }
        public ActionResult AddComment(CommentsVM comment, int postId)
        {
            //bool result = false;
            Comment commentEntity = null;

            string currentUserId = User.Identity.GetUserId();
            //  int userId = 1;
            //int.Parse(currentUserId);
            //(int)Session["UserID"];
            List <User> GetUsers = sp.GetUsers();

            var user = GetUsers.FirstOrDefault(u => u.Id == currentUserId);
            var post = sp.GetPosts().FirstOrDefault(p => p.PostID == postId);

            if (comment != null)
            {
                commentEntity = new Comment
                {
                    CommentMsg    = comment.CommentMsg,
                    CommentedDate = DateTime.Now
                                    //comment.CommentedDate,
                };


                if (user != null && post != null)
                {
                    post.Comments.Add(commentEntity);
                    user.Comments.Add(commentEntity);
                    //sq.SaveChanges( );
                    //dbContext.SaveChanges();
                    //result = true;

                    sp.Commit();
                    su.Commit();
                }
            }

            return(RedirectToAction("GetComments", "Comments", new { postId = postId }));
        }
Beispiel #30
0
        public async Task <IActionResult> Update([FromBody] CommentsVM model)
        {
            try
            {
                Comments cmt = new Comments()
                {
                    _id               = ObjectId.Parse(model._id),
                    Subject           = model.Subject,
                    ResponsiblePerson = model.ResponsiblePerson,
                    Completed         = model.Completed
                };


                await _commentRepository.UpdateComment(cmt);

                return(new OkObjectResult(cmt));
            }
            catch (Exception ex)
            {
            }
            return(Ok());
        }