Beispiel #1
0
        public ActionResult CommentsList(CommentsViewModel model, CommentViewModel newComment, string action)
        {
            if (action != null)
            {
                var comments = model.Comments;
                if (action.ToLower().StartsWith("delete"))
                {
                    var delete = int.Parse(action.Substring(7));
                    comments = comments.Take(delete).Concat(comments.Skip(delete + 1).Take(comments.Count() - 1 - delete));
                }

                if (action.ToLower().StartsWith("add"))
                {
                    if (comments == null)
                    {
                        comments = new CommentViewModel[] { }
                    }
                    ;
                    comments = comments.Concat(new[] { newComment });
                }

                model.Comments = comments;
            }
            ViewBag.Users = UserService.GetUsers().Select(user => user.ToViewModel()).ToDictionary(x => x.Id, x => x.FullName);
            return(View("CommentsList", model));
        }