コード例 #1
0
        public ActionResult Create(CreateReview formModel, int Id)
        {
            var email = User.Identity.Name;

            var revRepo  = new ReviewsRepo(context);
            var benRepo  = new BenchRepo(context);
            var userRepo = new UserRepo(context);

            try
            {
                Bench bench  = benRepo.GetById(Id);
                User  user   = userRepo.GetByEmail(email);
                var   review = new Review(formModel.Rating, formModel.Comment, bench, user);
                review.CreatedOn = DateTime.UtcNow;
                revRepo.Insert(review);
                return(RedirectToAction("Index", "Bench"));
            }
            catch (DbUpdateException ex)
            {
                //HandleDbUpdateException(ex);
            }

            return(View("Create", formModel));
        }
コード例 #2
0
        public ActionResult Details(int benchId)
        {
            var formModel  = new CreateBench();
            var benchRepo  = new BenchRepo(context);
            var reviewRepo = new ReviewsRepo(context);
            var userRepo   = new UserRepo(context);

            Bench bench = benchRepo.GetById(benchId);
            User  user  = userRepo.GetById(bench.UserId);


            string phrase = user.Name;

            string[]      names    = phrase.Split(' ');
            string        lastName = names[1];
            StringBuilder uTag     = new StringBuilder(names[0]);

            uTag.Append(" " + lastName[0]);
            formModel.userTag = uTag.ToString();

            //string name = user.Name;
            //StringBuilder firstName = new StringBuilder();
            //StringBuilder lastInit = new StringBuilder();
            //bool enterLast = false;
            //for(int i = 0; i<name.Length; i++)
            //{
            //    if (name[i]==' ')
            //    {
            //        firstName.Append(' ');
            //    }
            //    else if(name[i]!=' ')
            //    {
            //        firstName.Append(name[i]);
            //    }
            //}
            formModel.Description = bench.Description;
            formModel.NumSeats    = bench.NumSeats;
            formModel.Latitude    = bench.Latitude;
            formModel.Longitude   = bench.Longitude;
            IList <Review> allReviews = reviewRepo.GetAllReviewsById(benchId);

            if (allReviews.Count == 0)
            {
                formModel.AverageRating = null;
            }
            else
            {
                float sum = 0f;
                foreach (Review rev in allReviews)
                {
                    sum += rev.Rating;
                }
                sum /= allReviews.Count;
                formModel.AverageRating = sum;
            }
            string        desc = formModel.Description;
            StringBuilder sb   = new StringBuilder();

            int wordCount = 0;

            for (int i = 0; i < desc.Length; i++)
            {
                sb.Append(desc[i]);
                if (desc[i] == ' ')
                {
                    wordCount++;
                }
                if (wordCount == 10)
                {
                    sb.Append("...");
                    break;
                }
            }
            formModel.Description = sb.ToString();

            return(View(formModel));
        }
コード例 #3
0
 public ReviewsController(ReviewsRepo repo)
 {
     _repo = repo;
 }