Ejemplo n.º 1
0
        public CardComment Create(CardComment comment)
        {
            if (comment is null)
            {
                throw new ArgumentNullException(nameof(comment));
            }

            _context.CardComments.Add(comment);
            _context.SaveChanges();

            return(comment);
        }
Ejemplo n.º 2
0
        public void Update(CardComment comment)
        {
            if (comment is null)
            {
                throw new ArgumentNullException(nameof(comment));
            }
            if (_context.CardComments.SingleOrDefault(x => x.Id == comment.Id) is null)
            {
                throw new AppException("Card Comment not found.");
            }

            _context.CardComments.Update(comment);
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("CardCommentId,CardId,UserId,Comment")] CardComment cardComment, int id)
        {
            var user = await GetCurrentUserAsync();

            cardComment.CardId = id;
            cardComment.UserId = user.Id;
            if (ModelState.IsValid)
            {
                _context.Add(cardComment);
                await _context.SaveChangesAsync();

                return(RedirectToAction("GetUserCardComments", new { id = id }));
            }

            return(View(cardComment));
        }
Ejemplo n.º 4
0
        public CommandResult <bool> Execute(RedfernDb db)
        {
            CardComment comment = db.CardComments.Find(this.CardCommentId);

            Activity activity = db.Activities.Create();

            activity.ActivityDate = DateTime.UtcNow;
            activity.SetVerb("deleted");
            activity.SetActor(db.Context.ClientUserName, db.Context.ClientUserFullName);
            activity.SetObject("comment", comment.CommentId.ToString(), "", "");
            activity.SetSource("card", comment.CardId.ToString(), comment.Card.Title, "");
            activity.SetContext("board", comment.Card.BoardId.ToString(), comment.Card.Board.Name, String.Format(@"/board/{0}", comment.Card.BoardId));
            activity.SetDescription("<b>{actorlink}</b> deleted <b>{object}</b> from {sourcelink} in {contextlink}");
            activity = db.Activities.Add(activity);

            db.CardComments.Remove(comment);
            db.SaveChanges();

            return(this.CommandResult <bool>(true, db, activity));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("CardCommentId, Comment, UserId, CardId")] CardComment cardComment)
        {
            var user = await GetCurrentUserAsync();

            cardComment.UserId = user.Id;
            cardComment.CardId = _context.CardComment.AsNoTracking().FirstOrDefault(cc => cc.CardCommentId == id).CardId;



            if (id != cardComment.CardCommentId)
            {
                return(NotFound());
            }



            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cardComment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CardCommentExists(cardComment.CardCommentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("GetUserCardComments", new { id = cardComment.CardId }));
            }

            return(View(cardComment));
        }