Skip to content

Instantly share code, notes, and snippets.

@aidanmorgan
Created June 16, 2011 16:18
Show Gist options
  • Save aidanmorgan/1029607 to your computer and use it in GitHub Desktop.
Save aidanmorgan/1029607 to your computer and use it in GitHub Desktop.
public RatingDTO Create(Guid userId, Guid whiskeyId, int score, string review = "")
{
using(IUnitOfWork uow = _unitOfWorkFactory.Create("RatingService.Create"))
{
Rating r = uow.RatingRepository.All().Where(x => x.ReviewOf.Id == whiskeyId && x.ReviewedBy.Id == userId).FirstOrDefault();
Whiskey w = uow.WhiskeyRepository.FindById(whiskeyId);
User u = uow.UserRepository.FindById(userId);
// there is no existing Rating in the system, so create a new one.))
if(r == null)
{
r = uow.RatingRepository.Create(w, u, score);
}
r.Review = review;
UpdateScores(w);
uow.Save();
return RatingDTO.Create(r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment