예제 #1
0
 public CommentDTO(TrainingComment comment)
 {
     ID       = comment.ID;
     Message  = comment.Comment;
     DateTime = comment.DateTime;
     Reply_ID = comment.Reply_Comment_ID;
     Login    = comment.User_Login;
 }
예제 #2
0
        public IActionResult AddNewTrainingComment([FromBody] CommentModel obj)
        {
            var comment = new TrainingComment
            {
                //TrainingCommentId = obj.CommentId,
                AuthorId   = obj.AuthorId,
                Content    = obj.Content,
                Date       = obj.Date,
                TrainingId = obj.TrainingId,
            };

            unitOfWork.TrainingCommentRepository.Insert(comment);
            unitOfWork.Commit();
            return(new ObjectResult(comment.TrainingCommentId));
        }
예제 #3
0
        public async Task <IActionResult> LiveComment(int id, [Bind("CommentContext")] TrainingComment comment)
        {
            if (ModelState.IsValid)
            {
                comment.TrainingId = id;
                comment.DogHandler = await _context.DogHandlers
                                     .Include(s => s.User)
                                     .FirstOrDefaultAsync(u => u.User.Email == User.Identity.Name);

                comment.Date = DateTime.Now;

                _context.TrainingComments.Add(comment);
                await _context.SaveChangesAsync();

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

            return(RedirectToAction("Index", "Home"));
        }
예제 #4
0
        public void AddTrainingComment(CommentDTO commentDTO, int id)
        {
            Training training = db.Trainings.Get(id);
            bool     todo     = false;

            if (training != null)
            {
                Coach coach = db.Coaches.Get(commentDTO.Login);
                if (coach != null)
                {
                    if (training.Course.Coach_Login != coach.Login)
                    {
                        todo = true;
                    }
                }
                Trainee trainee = db.Trainees.Get(commentDTO.Login);
                if (trainee != null)
                {
                    if (trainee.Member_in_Courses.Any(x => x.Course_Id == training.Course_ID))
                    {
                        todo = true;
                    }
                }
            }
            if (todo)
            {
                TrainingComment comment = new TrainingComment()
                {
                    Comment          = commentDTO.Message,
                    DateTime         = DateTime.Now,
                    Reply_Comment_ID = commentDTO.Reply_ID,
                    User_Login       = commentDTO.Login,
                    Training_Id      = id
                };
                db.TrainingComments.Create(comment);
                db.Save();
            }
        }