<commit_before>﻿using Core.DomainModel;
using Core.DomainModel.Advice;
using Core.DomainModel.AdviceSent;
using Core.DomainModel.ItContract;
using Core.DomainModel.ItProject;
using Core.DomainModel.ItSystem;
using Core.DomainServices;
using Hangfire;
using Ninject;
using System;
using System.Linq;
using System.Net.Mail;
using System.Text;

namespace Core.ApplicationServices
{
    using Ninject.Extensions.Logging;

    public class AdviceService: IAdviceService
    {
        [Inject]
        public MailClient _mailClient {  get; set; }
        [Inject]
        public IGenericRepository<User> _userRepository { get; set;}
        [Inject]
        public IGenericRepository<Advice> _adviceRepository { get; set; }
        [Inject]
        public IGenericRepository<AdviceSent> _adviceSentRepository { get; set; }
        [Inject]
        public IGenericRepository<ItContractRight> _ItContractRights { get; set; }
        [Inject]
        public IGenericRepository<ItProjectRight> _ItprojectRights { get; set; }
        [Inject]
        public IGenericRepository<ItSystemRight> _ItSystemRights { get; set; }
        [Inject]
        public ILogger Logger { get; set; }

        public AdviceService() {}

        public bool sendAdvice(int id){
            Logger.Debug($"Host: {_mailClient._client.Host}, SSL: {_mailClient._client.EnableSsl}");
            var advice = _adviceRepository.AsQueryable().FirstOrDefault(a => a.Id == id);

            if (advice != null)
            {
                if (advice.Scheduling == Scheduling.Immediate)
                {
                    try
                    {
                        //Setup mail
                        MailMessage message = new MailMessage()
                        {
                            Body = advice.Body,
                            Subject = (advice.Subject).Replace('\r', ' ').Replace('\n', ' '),
                            BodyEncoding = Encoding.UTF8
                        };

                        message.From = new MailAddress("<EMAIL>");

                        //Add recivers for Email
                        foreach (var r in advice.Reciepients)
                        {
                            if (r.RecieverType == RecieverType.RECIEVER && r.RecpientType == RecieverType.USER)
                            {
                                message.To.Add(r.Name);
                            }
                            if (r.RecieverType == RecieverType.CC && r.RecpientType == RecieverType.USER)
                            {
                                message.CC.Add(r.Name);
                            }
                            if (r.RecieverType == RecieverType.CC && r.RecpientType == RecieverType.ROLE)
                            {

                                switch (advice.Type)
                                {
                                    case ObjectType.itContract:

                                        var result = _ItContractRights.AsQueryable().FirstOrDefault(I => I.ObjectId == advice.RelationId
                                       && I.Role.Name == r.Name);
                                        if (result != null)
                                        {<commit_msg>From mail outcommented<commit_after>﻿using Core.DomainModel;
using Core.DomainModel.Advice;
using Core.DomainModel.AdviceSent;
using Core.DomainModel.ItContract;
using Core.DomainModel.ItProject;
using Core.DomainModel.ItSystem;
using Core.DomainServices;
using Hangfire;
using Ninject;
using System;
using System.Linq;
using System.Net.Mail;
using System.Text;

namespace Core.ApplicationServices
{
    using Ninject.Extensions.Logging;

    public class AdviceService: IAdviceService
    {
        [Inject]
        public MailClient _mailClient {  get; set; }
        [Inject]
        public IGenericRepository<User> _userRepository { get; set;}
        [Inject]
        public IGenericRepository<Advice> _adviceRepository { get; set; }
        [Inject]
        public IGenericRepository<AdviceSent> _adviceSentRepository { get; set; }
        [Inject]
        public IGenericRepository<ItContractRight> _ItContractRights { get; set; }
        [Inject]
        public IGenericRepository<ItProjectRight> _ItprojectRights { get; set; }
        [Inject]
        public IGenericRepository<ItSystemRight> _ItSystemRights { get; set; }
        [Inject]
        public ILogger Logger { get; set; }

        public AdviceService() {}

        public bool sendAdvice(int id){
            Logger.Debug($"Host: {_mailClient._client.Host}, SSL: {_mailClient._client.EnableSsl}");
            var advice = _adviceRepository.AsQueryable().FirstOrDefault(a => a.Id == id);

            if (advice != null)
            {
                if (advice.Scheduling == Scheduling.Immediate)
                {
                    try
                    {
                        //Setup mail
                        MailMessage message = new MailMessage()
                        {
                            Body = advice.Body,
                            Subject = (advice.Subject).Replace('\r', ' ').Replace('\n', ' '),
                            BodyEncoding = Encoding.UTF8
                        };

                       // message.From = new MailAddress("<EMAIL>");

                        //Add recivers for Email
                        foreach (var r in advice.Reciepients)
                        {
                            if (r.RecieverType == RecieverType.RECIEVER && r.RecpientType == RecieverType.USER)
                            {
                                message.To.Add(r.Name);
                            }
                            if (r.RecieverType == RecieverType.CC && r.RecpientType == RecieverType.USER)
                            {
                                message.CC.Add(r.Name);
                            }
                            if (r.RecieverType == RecieverType.CC && r.RecpientType == RecieverType.ROLE)
                            {

                                switch (advice.Type)
                                {
                                    case ObjectType.itContract:

                                        var result = _ItContractRights.AsQueryable().FirstOrDefault(I => I.ObjectId == advice.RelationId
                                       && I.Role.Name == r.Name);
                                        if (result != null)
                                        {
{'fraction_non_alphanumeric': 0.08909512761020881, 'fraction_numerical': 0.0003093580819798917, 'mean_word_length': 1.3117626027887022, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707063', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1585, 'n_words': 322}