Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,MagazineArticleID,Comment,UserID,CreatedDated,status")] SegmentArticleComment magazineArticleComment)
        {
            if (id != magazineArticleComment.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(magazineArticleComment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MagazineArticleCommentExists(magazineArticleComment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(magazineArticleComment));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ID,MagazineArticleID,Comment,UserID,CreatedDated,status")] SegmentArticleComment magazineArticleComment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(magazineArticleComment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(magazineArticleComment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Comment,CreatedDate")] SegmentArticleComment segmentArticleComment)
        {
            if (id != segmentArticleComment.ID)
            {
                return(NotFound());
            }
            var articleID = HttpContext.Session.GetInt32("ArticleID") ?? 0;

            if (ModelState.IsValid)
            {
                try
                {
                    //When we edit the old fields except the ones being edited are wiped. So I needed to
                    //lookup the old one then overwrite it as neeed
                    var oldComment = _context.SegmentArticleComment.FirstOrDefault(p => p.ID == id);
                    oldComment.Comment    = segmentArticleComment.Comment;
                    segmentArticleComment = oldComment;
                    _user = _userManager.GetUserAsync(User).GetAwaiter().GetResult();
                    segmentArticleComment.CompanyID = _user.companyID;
                    segmentArticleComment.UserID    = _user.Id;
                    segmentArticleComment.UserName  = _user.UserName;
                    segmentArticleComment.EditDate  = DateTime.Now;
                    segmentArticleComment.Status    = "Review";

                    segmentArticleComment.SegmentArticleID = articleID;
                    _context.Update(segmentArticleComment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SegmentArticleCommentExists(segmentArticleComment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", new { id = articleID }));
            }
            return(View(segmentArticleComment));
        }
        public async Task <IActionResult> Create(SegmentArticleComment segmentArticleComment)
        {
            if (ModelState.IsValid)
            {
                var articleID = HttpContext.Session.GetInt32("ArticleID") ?? 0;
                _user = _userManager.GetUserAsync(User).GetAwaiter().GetResult();
                SegmentArticleComment sgc = new SegmentArticleComment();

                sgc.CompanyID   = _user.companyID;
                sgc.UserID      = _user.Id;
                sgc.UserName    = _user.UserName;
                sgc.CreatedDate = DateTime.Now;
                sgc.Status      = "Review";
                sgc.Comment     = segmentArticleComment.Comment;

                sgc.SegmentArticleID = articleID;
                _context.Add(sgc);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = articleID }));
            }
            return(View(segmentArticleComment));
        }
        public async Task <IActionResult> ApproveReply(SegmentArticleComment segmentArticleComment)
        {
            if (ModelState.IsValid)
            {
                var articleID          = HttpContext.Session.GetInt32("ArticleID") ?? 0;
                var commentToApproveID = HttpContext.Session.GetInt32("CommentToApprove") ?? 0;
                _user = _userManager.GetUserAsync(User).GetAwaiter().GetResult();
                SegmentArticleComment sgc = new SegmentArticleComment();

                //First of all approve the orignal comment
                var sac = await _context.SegmentArticleComment.FindAsync(commentToApproveID);

                if (sac == null)
                {
                    return(NotFound());
                }
                sac.Status = "Approved";

                // Create the new comment but set the ReplyingToCommentID field
                sgc.CompanyID = _user.companyID;
                sgc.UserID    = _user.Id;
                sgc.UserName  = _user.UserName;
                //set the created date to be just after the original message so it is next
                sgc.CreatedDate         = sac.CreatedDate.AddMilliseconds(1);
                sgc.Status              = "Approved";
                sgc.Comment             = segmentArticleComment.Comment;
                sgc.ReplyingToCommentID = commentToApproveID;

                sgc.SegmentArticleID = sac.SegmentArticleID;
                _context.Add(sgc);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Admin", new { id = _user.companyID }));
            }
            return(View(segmentArticleComment));
        }