Ejemplo n.º 1
0
        public Rating AddNew(Rating rating)
        {
            this.ratings.Add(rating);

            this.ratings.SaveChanges();

            return rating;
        }
        public int AddNew(int rating, string userId, string authorId)
        {
            var newRating = new Rating()
            {
                Value = rating,
                FreelancerID = userId,
                EmployerID = authorId
            };

            this.ratings.Add(newRating);
            this.ratings.SaveChanges();

            return newRating.Id;
        }
Ejemplo n.º 3
0
        public void CreateRating(int fieldId, string creatorUsername, int value)
        {
            var creator = this.userService.GetByUsername(creatorUsername).FirstOrDefault();
            var field = this.fields.All().Where(x => x.Id == fieldId).FirstOrDefault();

            var rating = new Rating
            {
                Creator = creator,
                SportField = field,
                Value = value
            };

            this.ratings.Add(rating);
            this.ratings.SaveChanges();

        }
Ejemplo n.º 4
0
                public async Task <Response> Handle(Command request, CancellationToken cancellationToken)
                {
                    // ignore undecided ones for now (they could pop again later...)
                    if (request.Score == ScoreType.UNDECIDED)
                    {
                        return(new());
                    }

                    var user = await CurrentUserAccessor.CurrentUser();

                    var rating = new Models.Rating()
                    {
                        User      = user,
                        TitleId   = request.MovieId,
                        SessionId = request.SessionId,
                        Score     = request.Score
                    };

                    SessionRepository.AddRating(rating);
                    await SessionRepository.Save();

                    return(new());
                }
Ejemplo n.º 5
0
        private static void SeedRatings(string jsonRatings, MoviesModel context)
        {
            var ratings = JArray.Parse(jsonRatings);
            foreach (JToken rating in ratings)
            {
                string isbn = rating["movie"].ToString();
                string user = rating["user"].ToString();

                int movieId = context.Movies.FirstOrDefault(m => m.Isbn == isbn).Id;
                int userId = context.Users.FirstOrDefault(u => u.Username == user).Id;

                Rating dbRating = new Rating()
                {
                    MovieId = movieId,
                    UserId = userId,
                    Stars = int.Parse(rating["rating"].ToString())
                };
                context.Ratings.Add(dbRating);
            }
            context.SaveChanges();
        }
Ejemplo n.º 6
0
        public void RateRecipe(AuthIdentity identity, Guid recipeId, Rating rating)
        {
            using (var session = this.GetSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var existingRate = session.QueryOver<RecipeRatings>()
                       .Where(p => p.UserId == identity.UserId)
                       .Where(p => p.Recipe.RecipeId == recipeId)
                       .SingleOrDefault();

                    if (existingRate != null)
                    {
                        existingRate.Rating = (byte)rating;
                        session.Update(existingRate);
                    }
                    else
                    {
                        session.Save(new RecipeRatings
                        {
                            UserId = identity.UserId,
                            Recipe = new Recipes { RecipeId = recipeId },
                            Rating = (byte)rating
                        });
                    }

                    transaction.Commit();
                }
            }
        }
Ejemplo n.º 7
0
 public void AddRating(Rating rating)
 {
     rating.Date = DateTimeOffset.UtcNow;
     _db.Ratings.Insert(rating);
 }