示例#1
0
        public Rating CreateTestRating(UserProfile user, Link link, int value)
        {
            Rating rating = Rating.CreateRating(
                TestData.nonExistentRatingId,
                user.userId,
                link.linkId,
                value,
                Trunk(DateTime.Now));

            RatingDao.Create(rating);

            return(rating);
        }
示例#2
0
        private void OnAdd(object obj)
        {
            var dataRepository = Container.GetInstance <IDataRepository>();

            if (dataRepository.TrainingRatings.Any(r => r.User == SelectedUser && r.Movie == SelectedMovie))
            {
                MessageBox.Show("Taka ocena jest już w bazie", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
                RatingValue = 3.0;
                return;
            }

            dataRepository.TrainingRatings.Add(Rating.CreateRating(SelectedUser, SelectedMovie, RatingValue));
            RatingValue = 3.0;

            RaiseOnWindowUpdated(this, EventArgs.Empty);
        }
示例#3
0
        public long Rate(long userId, long linkId, int value)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            Link link;

            try
            {
                link = LinkDao.Find(linkId);
            }
            catch (InstanceNotFoundException <Link> ex)
            {
                throw new InstanceNotFoundException <LinkDetails>(ex.Properties);
            }

            if (link.UserProfile.userId == userId)
            {
                throw new UserNotAuthorizedException <RatingDetails>(userId, "linkId", linkId);
            }

            if (!RatingDao.ExistsForUserAndLink(userId, linkId))
            {
                if (value == 0)
                {
                    return(-1);
                }

                Rating rating = Rating.CreateRating(-1, userId, linkId, value, DateTime.Now);
                try
                {
                    RatingDao.Create(rating);
                }
                catch (DuplicateInstanceException <Rating> ex)
                {
                    throw new InternalErrorException(ex);
                }

                return(rating.ratingId);
            }
            else
            {
                Rating rating;
                try
                {
                    rating = RatingDao.FindForUserAndLink(userId, linkId);
                }
                catch (InstanceNotFoundException <Rating> ex)
                {
                    throw new InternalErrorException(ex);
                }
                catch (DuplicateInstanceException <Rating> ex)
                {
                    throw new InternalErrorException(ex);
                }

                if (value == 0)
                {
                    try
                    {
                        RatingDao.Remove(rating.ratingId);
                    }
                    catch (InstanceNotFoundException <Rating> ex)
                    {
                        throw new InternalErrorException(ex);
                    }
                    return(-1);
                }

                rating.value = value;
                try
                {
                    RatingDao.Update(rating);
                }
                catch (InstanceNotFoundException <Rating> ex)
                {
                    throw new InternalErrorException(ex);
                }

                return(rating.ratingId);
            }
        }
示例#4
0
 public Rating BuildInterface()
 {
     return(Rating.CreateRating(this.Id, this.Uid, this.Name));
 }