예제 #1
0
        public ImageMoodViewModel AddMood(Mood mood, int imageId)
        {
            if (mood == null) throw new ArgumentNullException("mood");

            if (IsMoodExists(mood.Name, imageId))
            {
                throw new ArgumentException("Mood already exist for image");
            }

            var existingMood = _moodRepository.Find(x => x.Name.ToUpper() == mood.Name.ToUpper(), i => i.MoodToImages);
            var moodToAdd = existingMood ?? mood;

            var image = _imageRepository.Find(imageId);

            image.AddMood(moodToAdd, UserContext);

            _imageRepository.SaveChanges();

            var moodToImage = moodToAdd.MoodToImages.First(x => x.ImageId == imageId);

            return new ImageMoodViewModel
                {
                    Id = moodToImage.Id,
                    Mood = new MoodViewModel
                        {
                            Id = moodToImage.Mood.Id,
                            Name = moodToImage.Mood.Name
                        },
                        Rating = moodToImage.Rating,
                        Voted = true
                };
        }
예제 #2
0
 public virtual ActionResult AddMood(Mood mood, int imageId)
 {
     var imageMoodViewModel = _moodsService.AddMood(mood, imageId);
     return View(imageMoodViewModel);
 }
예제 #3
0
 public void AddMood(Mood mood, UserContext userContext)
 {
     if (mood.Id == 0)
     {
         mood.Create();
     }
     var moodToImage = new MoodToImage {Mood = mood};
     moodToImage.Vote(userContext.UserGuid);
     ImageMoods.Add(moodToImage);
 }