<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nl.fhict.IntelliCloud.Common.DataTransfer;
using nl.fhict.IntelliCloud.Data.Model;

namespace nl.fhict.IntelliCloud.Business
{
    /// <summary>
    /// This class will implement methods for converting Entities to domain objects.
    /// Only if it is necessary.
    /// </summary>
    public class ConvertEntities
    {
        /// <summary>
        /// Converts a UserEntity object to a User object.
        /// </summary>
        /// <param name="entity">The UserEntity that has to be converted.</param>
        /// <returns>The user object.</returns>
        public User UserEntityToUser(UserEntity entity)
        {
            User user = new User();
            user.Id = entity.Id;
            user.FirstName = entity.FirstName;
            user.Infix = entity.Infix;
            user.LastName = entity.LastName;
            user.Type = entity.Type;
            user.CreationTime = entity.CreationTime;
            user.Sources = SourceEntityListToSources(entity.Sources);

            return user;
        }

        /// <summary>
        /// Converts a list of SourceEntities to a list of Sources.
        /// </summary>
        /// <param name="sourceEntities">The SourceEntities that have to be converted.</param>
        /// <returns>The list of sources.</returns>
        public List<Source> SourceEntityListToSources(ICollection<SourceEntity> sourceEntities)
        {
            List<Source> sources = new List<Source>();
            foreach (SourceEntity source in sourceEntities)
            {
                Source temp = new Source();
                temp.Id = source.Id;
                temp.SourceDefinition = SourceDefinitionEntityToSourceDefinition(source.SourceDefinition);
                temp.Value = source.Value;
                temp.CreationTime = source.CreationTime;
                sources.Add(temp);
            }
            return sources;
        }

        /// <summary>
        /// Converts a SourceDefinitionEntity to a SourceDefinition.
        /// </summary>
        /// <param name="sourceDefinitionEntity">The SourceDefinitionEntity that have to be converted.</param>
        /// <returns>The sourcedefinition object.</returns>
        public SourceDefinition SourceDefinitionEntityToSourceDefinition(
            SourceDefinitionEntity sourceDefinitionEntity)
        {
            SourceDefinition sourceDefinition = new SourceDefinition();
            sourceDefinition.Id = sourceDefinitionEntity.Id;
            sourceDefinition.Name = sourceDefinitionEntity.Name;
            sourceDefinition.Description = sourceDefinitionEntity.Description;
            sourceDefinition.CreationTime = sourceDefinitionEntity.CreationTime;
            return sourceDefinition;
        }

        /// <summary>
        /// Converts a QuestionEntity to a Question.
        /// </summary>
        /// <param name="entity">The QuestionEntity that has to be converted.</param>
        /// <returns>The question object.</returns>
        public Question QuestionEntityToQuestion(QuestionEntity entity)
        {
            Question question = new Question();
            question.Id = entity.Id;
            if (entity.Answerer != null)
            {
                question.Answerer = UserEntityToUser(entity.Answerer);
            }
            question.User = UserEntityToUser(entity.User);
            question.Content = entity.Content;
            question.CreationTime = entity.CreationTime;
            question.QuestionState = entity.QuestionState;
            question.SourceDefinition = SourceDefinitionEntityToSourceDefinition(entity.SourceDefinition);
            return question;
        }

        /// <summary>
        /// Converts an AnswerEntity to an Answer.
        /// </summary>
        /// <param name="entity">The AnswerEntity that has to be converted.</param>
        /// <returns>The Answer object.</returns>
        public Answer AnswerEntityToAnswer(AnswerEntity entity)
        {
            Answer answer = new Answer();

            answer.Id = entity.Id;
            answer.CreationTime = entity.CreationTime;
            answer.Content = entity.Content;
            answer.AnswerState = entity.AnswerState;
            answer.User = UserEntityToUser(entity.User);

            return answer;
        }

        /// <summary>
        /// Converts a list of AnswerEntities to a list of Answers.
        /// </summary>
        /// <param name="entities">The AnswerEntities that have to be converted.</param>
        /// <returns>The list of answers.</returns>
        public List<Answer> AnswerEntityListToAnswerList(List<AnswerEntity> entities)
        {
            List<Answer> answers = new List<Answer>();
            foreach (AnswerEntity entity in entities)
            {                
                answers.Add(AnswerEntityToAnswer(entity));
            }

            return answers;
        }

        /// <summary>
        /// Converts a list of ReviewEntities to a list of Reviews.
        /// </summary>
        /// <param name="entities">The ReviewEntities that have to be converted.</param>
        /// <returns>The list of reviews.</returns>
        public List<Review> ReviewEntityListToReviewList(List<ReviewEntity> entities)
        {
            List<Review> reviews = new List<Review>();
            foreach (ReviewEntity entity in entities)
            {
                Review temp = new Review();
                temp.Id = entity.Id;
                temp.Content = entity.Content;
                temp.ReviewState = entity.ReviewState;
                temp.AnswerId = entity.Answer.Id;
                temp.CreationTime = entity.CreationTime;
                temp.User = this.UserEntityToUser(entity.User);
                reviews.Add(temp);
            }

            return reviews;
        }

        /// <summary>
        /// Converts a list of QuestionEntities to a list of Questions.
        /// </summary>
        /// <param name="entities">The QuestionEntities that have to be converted.</param>
        /// <returns>The list of questions.</returns>
        public List<Question> QuestionEntityListToQuestionList(List<QuestionEntity> entities)
        {
            List<Question> questions = new List<Question>();
            foreach (QuestionEntity entity in entities)
            {
                questions.Add(QuestionEntityToQuestion(entity));
            }
            return questions;
        }

        /// <summary>
        /// Method for converting a FeedbackEntity instance to a Feedback instance.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Instance of class Feedback.</returns>
        public Feedback FeedbackEntityToFeedback(FeedbackEntity entity)
        {
            Feedback feedback = new Feedback();

            feedback.Content = entity.Content;
            feedback.AnswerId = entity.Answer.Id;
            feedback.QuestionId = entity.Question.Id;
            feedback.User = UserEntityToUser(entity.User);
            feedback.FeedbackType = entity.FeedbackType;
            feedback.FeedbackState = entity.FeedbackState;
            feedback.CreationTime = entity.CreationTime;

            return feedback;
        }

        /// <summary>
        /// Method that converts a list of FeedbackEntity instances to a list of Feedback instances.
        /// </summary>
        /// <param name="entities">The list of FeedbackEntity instances to convert.</param>
        /// <returns>List of Feedback instances.</returns>
        public List<Feedback> FeedbackEntityListToFeedbackList(List<FeedbackEntity> entities)
        {
            List<Feedback> feedbacks = new List<Feedback>();

            foreach (FeedbackEntity entity in entities)
            {
                feedbacks.Add(FeedbackEntityToFeedback(entity));
            }

            return feedbacks;
        }
    }
}
<commit_msg>Removed unnecessary code, updated conversion code<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nl.fhict.IntelliCloud.Common.DataTransfer;
using nl.fhict.IntelliCloud.Data.Model;

namespace nl.fhict.IntelliCloud.Business
{
    /// <summary>
    /// This class will implement methods for converting Entities to domain objects.
    /// Only if it is necessary.
    /// </summary>
    public class ConvertEntities
    {
        /// <summary>
        /// Converts a UserEntity object to a User object.
        /// </summary>
        /// <param name="entity">The UserEntity that has to be converted.</param>
        /// <returns>The user object.</returns>
        public User UserEntityToUser(UserEntity entity)
        {
            User user = new User();
            user.Id = entity.Id;
            user.FirstName = entity.FirstName;
            user.Infix = entity.Infix;
            user.LastName = entity.LastName;
            user.Type = entity.Type;
            user.CreationTime = entity.CreationTime;
            user.Sources = SourceEntityListToSources(entity.Sources);

            return user;
        }

        /// <summary>
        /// Converts a list of SourceEntities to a list of Sources.
        /// </summary>
        /// <param name="sourceEntities">The SourceEntities that have to be converted.</param>
        /// <returns>The list of sources.</returns>
        public List<Source> SourceEntityListToSources(ICollection<SourceEntity> sourceEntities)
        {
            List<Source> sources = new List<Source>();
            foreach (SourceEntity source in sourceEntities)
            {
                Source temp = new Source();
                temp.Id = source.Id;
                temp.SourceDefinition = SourceDefinitionEntityToSourceDefinition(source.SourceDefinition);
                temp.Value = source.Value;
                temp.CreationTime = source.CreationTime;
                sources.Add(temp);
            }
            return sources;
        }

        /// <summary>
        /// Converts a SourceDefinitionEntity to a SourceDefinition.
        /// </summary>
        /// <param name="sourceDefinitionEntity">The SourceDefinitionEntity that have to be converted.</param>
        /// <returns>The sourcedefinition object.</returns>
        public SourceDefinition SourceDefinitionEntityToSourceDefinition(
            SourceDefinitionEntity sourceDefinitionEntity)
        {
            SourceDefinition sourceDefinition = new SourceDefinition();
            sourceDefinition.Id = sourceDefinitionEntity.Id;
            sourceDefinition.Name = sourceDefinitionEntity.Name;
            sourceDefinition.Description = sourceDefinitionEntity.Description;
            sourceDefinition.CreationTime = sourceDefinitionEntity.CreationTime;
            return sourceDefinition;
        }

        /// <summary>
        /// Converts a QuestionEntity to a Question.
        /// </summary>
        /// <param name="entity">The QuestionEntity that has to be converted.</param>
        /// <returns>The question object.</returns>
        public Question QuestionEntityToQuestion(QuestionEntity entity)
        {
            Question question = new Question();
            question.Id = entity.Id;
            if (entity.Answerer != null)
            {
                question.Answerer = UserEntityToUser(entity.Answerer);
            }
            question.User = UserEntityToUser(entity.User);
            question.Content = entity.Content;
            question.CreationTime = entity.CreationTime;
            question.QuestionState = entity.QuestionState;
            question.SourceDefinition = SourceDefinitionEntityToSourceDefinition(entity.SourceDefinition);
            return question;
        }

        /// <summary>
        /// Converts an AnswerEntity to an Answer.
        /// </summary>
        /// <param name="entity">The AnswerEntity that has to be converted.</param>
        /// <returns>The Answer object.</returns>
        public Answer AnswerEntityToAnswer(AnswerEntity entity)
        {
            Answer answer = new Answer();

            answer.Id = entity.Id;
            answer.CreationTime = entity.CreationTime;
            answer.Content = entity.Content;
            answer.AnswerState = entity.AnswerState;
            answer.User = UserEntityToUser(entity.User);

            return answer;
        }

        /// <summary>
        /// Converts a list of AnswerEntities to a list of Answers.
        /// </summary>
        /// <param name="entities">The AnswerEntities that have to be converted.</param>
        /// <returns>The list of answers.</returns>
        public List<Answer> AnswerEntityListToAnswerList(List<AnswerEntity> entities)
        {
            List<Answer> answers = new List<Answer>();
            foreach (AnswerEntity entity in entities)
            {                
                answers.Add(AnswerEntityToAnswer(entity));
            }

            return answers;
        }

        /// <summary>
        /// Converts a list of ReviewEntities to a list of Reviews.
        /// </summary>
        /// <param name="entities">The ReviewEntities that have to be converted.</param>
        /// <returns>The list of reviews.</returns>
        public List<Review> ReviewEntityListToReviewList(List<ReviewEntity> entities)
        {
            List<Review> reviews = new List<Review>();
            foreach (ReviewEntity entity in entities)
            {
                Review temp = new Review();
                temp.Id = entity.Id;
                temp.Content = entity.Content;
                temp.ReviewState = entity.ReviewState;
                temp.AnswerId = entity.Answer.Id;
                temp.CreationTime = entity.CreationTime;
                temp.User = this.UserEntityToUser(entity.User);
                reviews.Add(temp);
            }

            return reviews;
        }

        /// <summary>
        /// Converts a list of QuestionEntities to a list of Questions.
        /// </summary>
        /// <param name="entities">The QuestionEntities that have to be converted.</param>
        /// <returns>The list of questions.</returns>
        public List<Question> QuestionEntityListToQuestionList(List<QuestionEntity> entities)
        {
            List<Question> questions = new List<Question>();
            foreach (QuestionEntity entity in entities)
            {
                questions.Add(QuestionEntityToQuestion(entity));
            }
            return questions;
        }

        /// <summary>
        /// Method for converting a FeedbackEntity instance to a Feedback instance.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Instance of class Feedback.</returns>
        public Feedback FeedbackEntityToFeedback(FeedbackEntity entity)
        {
            // Construct and return a new instance of class Feedback, containing the data from the passed entity class
            return new Feedback()
            {
                Content = entity.Content,
                AnswerId = entity.Answer.Id,
                QuestionId = entity.Question.Id,
                User = UserEntityToUser(entity.User),
                FeedbackType = entity.FeedbackType,
                FeedbackState = entity.FeedbackState,
                CreationTime = entity.CreationTime
            };
        }
    }
}

{'fraction_non_alphanumeric': 0.09679516349216667, 'fraction_numerical': 0.0, 'mean_word_length': 1.8701492537313433, 'pattern_counts': {'":': 0, '<': 157, '<?xml version=': 0, '>': 157, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '131423', 'n_tokens_mistral': 3660, 'n_tokens_neox': 3559, 'n_words': 929}