Esempio n. 1
0
        public IHttpActionResult Review(AnonymousReviewBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var dbContext         = new ApplicationDbContext();
            var reviews           = new DeletableEntityRepository <ClubAnonymousReview>(dbContext);
            var clubs             = new DeletableEntityRepository <Club>(dbContext);
            var clubToAddReviewTo = clubs.GetById(model.ClubId);

            if (clubToAddReviewTo == null)
            {
                return(this.BadRequest());
            }

            var newAnonymousReview = new ClubAnonymousReview()
            {
                ClubId  = clubToAddReviewTo.Id,
                Content = model.Content,
                Rating  = model.Rating
            };

            reviews.Add(newAnonymousReview);
            return(this.Ok());
        }
Esempio n. 2
0
        public IHttpActionResult Vote(HiddenImageVoteBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest();
            }

            var dbContext = new ApplicationDbContext();
            var hiddenImages = new DeletableEntityRepository<ClubHiddenImage>(dbContext);
            var hiddenImageVotes = new DeletableEntityRepository<ClubHiddenImageVote>(dbContext);
            var image = hiddenImages.GetById(model.ImageId);
            var vote = new ClubHiddenImageVote()
            {
                ImageId = image.Id,
                Vote = model.Rating
            };

            hiddenImagesVotes.Add(vote);
            var rating = image.Votes.Sum(v => (int)v.Vote);
            return this.Ok(rating);
        }
Esempio n. 3
0
        public IHttpActionResult Vote(HiddenImageVoteBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var dbContext        = new ApplicationDbContext();
            var hiddenImages     = new DeletableEntityRepository <ClubHiddenImage>(dbContext);
            var hiddenImageVotes = new DeletableEntityRepository <ClubHiddenImageVote>(dbContext);
            var image            = hiddenImages.GetById(model.ImageId);
            var vote             = new ClubHiddenImageVote()
            {
                ImageId = image.Id,
                Vote    = model.Rating
            };

            hiddenImagesVotes.Add(vote);
            var rating = image.Votes.Sum(v => (int)v.Vote);

            return(this.Ok(rating));
        }
Esempio n. 4
0
        public IHttpActionResult Review(AnonymousReviewBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest();
            }

            var dbContext = new ApplicationDbContext();
            var reviews = new DeletableEntityRepository<ClubAnonymousReview>(dbContext);
            var clubs = new DeletableEntityRepository<Club>(dbContext);
            var clubToAddReviewTo = clubs.GetById(model.ClubId);
            if (clubToAddReviewTo == null)
            {
                return this.BadRequest();
            }

            var newAnonymousReview = new ClubAnonymousReview()
            {
                 ClubId = clubToAddReviewTo.Id,
                 Content = model.Content,
                 Rating = model.Rating
            };

            reviews.Add(newAnonymousReview);
            return this.Ok();
        }