Exemplo n.º 1
0
        public ActionResult Create(CreateCommentViewModel model)
        {
            var currentUser = userManager.GetUserAsync(HttpContext.User).Result.Id;

            if (ModelState.IsValid)
            {
                CommentDTO comment = new CommentDTO
                {
                    ExerciseId       = model.ExerciseId,
                    UserId           = currentUser,
                    UserName         = User.Identity.Name,
                    CommentText      = model.CommentText,
                    Rating           = model.Rating,
                    CreationDateTime = DateTime.Now
                };
                commentManager.Insert(comment);
                if (model.Rating != null)
                {
                    var    commentlist = commentManager.Get(g => g.ExerciseId == model.ExerciseId && g.Rating != 0).ToList();
                    double average     = 0;
                    foreach (var elem in commentlist)
                    {
                        if (elem.Rating != 0)
                        {
                            average += Convert.ToDouble(elem.Rating);
                        }
                    }

                    average = average / commentlist.Count;
                    exerciseManager.UpdateRating(model.ExerciseId, average);
                }
            }
            return(RedirectToAction("TaskView ", "ExerciseManagement", model.ExerciseId));
        }
Exemplo n.º 2
0
        public int AddComment(string text, int goodId)
        {
            var comment = new CommentDTO()
            {
                GoodId      = goodId,
                UserId      = Convert.ToInt32(User.Identity.GetUserId()),
                Description = text,
                Date        = DateTime.Now
            };

            return(commentManager.Insert(comment));
        }
Exemplo n.º 3
0
        public void Post(CommentDTO comment)
        {
            comment.CreationDateTime = DateTime.Now;
            commentManager.Insert(comment);
            if (comment.Rating != null)
            {
                var    commentlist = commentManager.Get(g => g.ExerciseId == comment.ExerciseId && g.Rating != 0).ToList();
                double average     = 0;
                foreach (var elem in commentlist)
                {
                    if (elem.Rating != 0)
                    {
                        average += Convert.ToDouble(elem.Rating);
                    }
                }

                average = average / commentlist.Count;
                if (average >= 0)
                {
                    exerciseManager.UpdateRating(comment.ExerciseId, average);
                }
            }
        }