예제 #1
0
        public ActionResult TrailReviewCreate(TrailReviewCreate model)
        {
            if (ModelState.IsValid)
            {
                var service = CreateTrailReviewService();

                if (service.ValidateTrailReviewCreate(model))
                {
                    TempData["SaveResult"] = "Review was created.";

                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData["FailResult"] = "User already has a review for this trail in the system. Please edit your existing review.";
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["FailResult"] = "Review was not able to be created.";
            }
            return(RedirectToAction("Index"));
        }
예제 #2
0
        //VALIDATE VISIT DATE ON CREATE
        public DateTime ValidateVisitDate(TrailReviewCreate model)
        {
            var todaysDate = DateTime.Today;

            if (model.VisitDate > todaysDate)
            {
                return(model.VisitDate = DateTime.Today);
            }

            else
            {
                return(model.VisitDate);
            }
        }
예제 #3
0
        //CREATE TRAIL REVIEW
        public bool CreateTrailReview(TrailReviewCreate model)
        {
            var entity =
                new TrailReview()
            {
                OwnerId   = _userId,
                TrailId   = model.TrailId,
                Title     = model.Title,
                Comment   = model.Comment,
                Score     = model.Score,
                VisitDate = ValidateVisitDate(model)
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.TrailReviews.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #4
0
        //VALIDATION OF TRAIL REVIEW CREATE
        public bool ValidateTrailReviewCreate(TrailReviewCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx
                    .TrailReviews
                    .Where(r => r.OwnerId == _userId && r.TrailId == model.TrailId && r.IsDeleted == false);

                if (query.Count() >= 1)
                {
                    return(false);
                }

                else
                {
                    return(CreateTrailReview(model));
                }
            }
        }