Example #1
0
        /// <summary>
        /// aktualizuje komentar v databaze
        /// </summary>
        /// <param name="commentId">id aktualizovaneho komentara</param>
        /// <param name="updatedContent">novy obsah</param>
        public async void UpdateComment(string commentId, string updatedContent)
        {
            if (!Context.User.Identity.IsAuthenticated || string.IsNullOrEmpty(updatedContent) || string.IsNullOrEmpty(commentId))
            {
                return;
            }
            using (var _db = new Kronika106DBContext())
            {
                EventComments curComment   = null;
                int           commentIdInt = -1;
                int.TryParse(commentId, out commentIdInt);
                if (commentIdInt <= 0)
                {
                    return;
                }
                curComment = _db.Forum.FirstOrDefault(c => c.ID == commentIdInt);
                if (curComment == null)
                {
                    return;
                }

                //ak ten co meni komentar nie je jeho majitel
                if (curComment.ApplicationUser.UserName != Context.User.Identity.Name)
                {
                    return;
                }
                curComment.Comment = updatedContent;
                await _db.SaveChangesAsync();
            }
            GetComments();
        }
Example #2
0
        //prida komentár do databázy
        public async void AddComment(string commentContent, string thumbPath, string idRootEvetStr)
        {
            if (!Context.User.Identity.IsAuthenticated || string.IsNullOrEmpty(commentContent))
            {
                return;
            }

            #region videoTime
            //TimeSpan? videoTime=null;
            //if (hiddenVideoPosition.Value != null)
            //{
            //    string seconds = hiddenVideoPosition.Value.Split('.')[0];
            //    if (!string.IsNullOrEmpty(seconds))
            //    {
            //        int sec = -1;
            //        if (int.TryParse(seconds, out sec))
            //        {
            //            videoTime = new TimeSpan(0, 0, sec);
            //        }
            //    }
            //}
            #endregion videoTime

            string trueQueryString = Server.UrlDecode(Request.QueryString["ID"]);
            using (var _db = new Kronika106DBContext())
            {
                int           idRootComment = -1;
                EventComments rootComment   = null;
                if (!string.IsNullOrEmpty(idRootEvetStr))
                {
                    int.TryParse(idRootEvetStr, out idRootComment);
                    if (idRootComment > 0)
                    {
                        rootComment     = _db.Forum.FirstOrDefault(c => c.ID == idRootComment);
                        trueQueryString = rootComment.EventId;
                    }
                }
                if (string.IsNullOrWhiteSpace(trueQueryString))
                {
                    return;
                }
                string          userId     = Context.User.Identity.Name;
                ApplicationUser user       = _db.Users.First(u => u.UserName == userId);
                EventComments   newComment = new EventComments()
                {
                    CreatedUTC = DateTime.UtcNow, EventId = trueQueryString, Comment = commentContent, ApplicationUser = user, ThumbPath = thumbPath, IsPhoto = forumType == ForumType.EventPhotoGallery, IsEvent = forumType == ForumType.Event, IsVideo = forumType == ForumType.EventVideoGallery, RootID = rootComment?.ID                                             /*, VideoPosition= videoTime*/
                };
                _db.Forum.Add(newComment);
                await _db.SaveChangesAsync();
            }
            GetComments();
        }
Example #3
0
 public async void DeleteComment(string commentId)
 {
     if (!Context.User.Identity.IsAuthenticated || string.IsNullOrEmpty(commentId))
     {
         return;
     }
     using (var _db = new Kronika106DBContext())
     {
         EventComments curComment   = null;
         int           commentIdInt = -1;
         int.TryParse(commentId, out commentIdInt);
         if (commentIdInt <= 0)
         {
             return;
         }
         curComment = _db.Forum.FirstOrDefault(c => c.ID == commentIdInt);
         if (curComment == null)
         {
             return;
         }
         //ak ten co meni komentar nie je jeho majitel
         if (curComment.ApplicationUser.UserName != Context.User.Identity.Name)
         {
             return;
         }
         var lstChilds = _db.Forum.Where(c => c.RootID == commentIdInt);
         foreach (var child in lstChilds)
         {
             child.RootID          = curComment.RootID;
             child.ThumbPath       = curComment.ThumbPath;
             child.ApplicationUser = child.ApplicationUser;
         }
         _db.Forum.Remove(curComment);
         await _db.SaveChangesAsync();
     }
     GetComments();
 }