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()); }
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); }
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)); }
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(); }