Esempio n. 1
0
        private static void InitializeRatings(List <string> unparsedRatings)
        {
            foreach (var unparsedRating in unparsedRatings)
            {
                string[] unparsedParams = unparsedRating.Split(",");

                int id = int.Parse(unparsedParams[0]);
                PostRatingChoice choice     = Enum.Parse <PostRatingChoice>(unparsedParams[1]);
                User             ratingUser = users.FirstOrDefault(user => user.Id == int.Parse(unparsedParams[2]));
                Post             ratingPost = posts.FirstOrDefault(post => post.Id == int.Parse(unparsedParams[3]));
                bool             isDeleted  = bool.Parse(unparsedParams[4]);

                if (isDeleted)
                {
                    continue;
                }

                PostRating ratingForDb = new PostRating(choice)
                {
                    Id   = id,
                    User = ratingUser,
                    Post = ratingPost
                };

                ratings.Add(ratingForDb);
                ratingUser?.Ratings.Add(ratingForDb);
                ratingPost?.Ratings.Add(ratingForDb);
            }
        }
Esempio n. 2
0
 public PostRating(PostRatingChoice ratingChoice)
 {
     this.IsPositive = ratingChoice == PostRatingChoice.Positive;
     this.IsNegative = ratingChoice == PostRatingChoice.Negative;
 }