示例#1
0
        public ActionResult GetClassesToReview()
        {
            var EnrolledClasses = _enrolledService.GetTableQuery().Where(e => e.StudentId == SessionDataHelper.UserId).ToList();
            var Class = new List<Class>();
            var Reviews = new List<ReviewClassViewModel>();

            foreach(var c in EnrolledClasses)
            {
                var temp =new ReviewClassViewModel();
                var tempClassReview = _reviewClassService.GetTableQuery().Where(r => r.ClassId == c.ClassId).Where(r => r.StudentId == SessionDataHelper.UserId).SingleOrDefault();
                var tempClass = _classService.GetById(c.ClassId);
                temp.Description = tempClass.Description;
                temp.ClassID = tempClass.Id;
                temp.StudentID = SessionDataHelper.UserId;
                if (tempClassReview != null)
                {
                    temp.TeacherName = tempClass.Teacher.User.FirstName+ " " +tempClass.Teacher.User.LastName;
                    temp.Comment = tempClassReview.Comment;
                    temp.Date = tempClassReview.Date;
                    temp.Rating = tempClassReview.Rating;
                }
                else
                {
                    temp.Comment = "Review this Class!";
                    temp.Date = DateTime.Today.Date;
                    temp.Rating = 0;
                }

                Reviews.Add( temp);
            }

            var records = Reviews;
            return Json(new { Result = "OK", Records = records });
        }
示例#2
0
        public ActionResult AddUpdateClassesToReview(ReviewClassViewModel review)
        {
            try
            {
                var ReviewClass = _reviewClassService.GetTableQuery().Where(e => e.StudentId == review.StudentID).ToList();
                var classdesc = _classService.GetById(review.ClassID);
                var record = new ReviewClassViewModel();
                if(ReviewClass.Count()>0)
                {
                    var update = new ReviewClass
                    {
                        Id=ReviewClass.SingleOrDefault().Id,
                        ClassId = review.ClassID,
                        Comment = review.Comment,
                        Date = DateTime.Today,
                        StudentId = review.StudentID,
                        Rating = review.Rating,
                    };
                    _reviewClassService.Update(update);

                    record = new ReviewClassViewModel
                    {
                        ClassID = review.ClassID,
                        Comment = review.Comment,
                        Date = DateTime.Today,
                        StudentID = review.StudentID,
                        Rating = review.Rating,
                        Description = classdesc.Description,
                    };
                }
                else
                {
                    var insert = new ReviewClass();
                    insert.ClassId = review.ClassID;
                    insert.Comment = classdesc.Description;
                    insert.Date = DateTime.Today;
                    insert.StudentId = review.StudentID;
                    insert.Rating = review.Rating;
                    _reviewClassService.Insert(insert);

                    record = new ReviewClassViewModel
                    {
                        ClassID = review.ClassID,
                        Comment = review.Comment,
                        Date = DateTime.Today,
                        StudentID = review.StudentID,
                        Rating = review.Rating,
                        Description = classdesc.Description,
                    };
                }

                return Json(new { Result = "OK", Record = record });
            }
            catch(Exception e)
            {
                throw new Exception(e.Message);
            }
        }