Пример #1
0
        public Guid GetStatusId(string registrationStatus)
        {
            Guid registrationStatusId = Guid.Empty;

            using (var context = crmConnection.GetContext())
            {
                registrationStatusId = context.new_registrationstatusSet
                                       .FirstOrDefault(x => x.new_name == registrationStatus).Id;
            }

            if (registrationStatusId == Guid.Empty)
            {
                log.Error("Registration Status Id was not retrieved");
            }
            else
            {
                log.Error("Registration Status Id was retrieved successfully");
            }

            return(registrationStatusId);
        }
        public IEnumerable <string> AllRegistrationReportEmails()
        {
            var result = string.Empty;

            using (var context = crmConnection.GetContext())
            {
                result = context.new_systemrulesSet
                         .FirstOrDefault(x => x.new_Slug == REGISTRATION_TASK_OWNERS_SLUG)
                         .new_RuleValue;
            }

            if (string.IsNullOrEmpty(result))
            {
                log.Error("Owners mails faild to retreive");
                return(Enumerable.Empty <string>());
            }

            log.Info($"E-mails were retreived");
            return(result.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
                   .ToList());
        }
Пример #3
0
        public IEnumerable <CaseRetreiveModel> AllActiveByTypeAndAccountId(HashSet <string> accountIds, int caseTypeCode, string caseTitle)
        {
            log.Info($"{nameof(AllActiveByTypeAndAccountId)} started. Input info is: CaseTypeCode: {caseTypeCode}, CaseTitle: {caseTitle}, Number of Ids for comparing: {accountIds.Count()}");
            try
            {
                using (var context = crmConnection.GetContext())
                {
                    //Create Option set value depending on Input
                    var targetType = new OptionSetValue(caseTypeCode);

                    var casesToSolve = context.IncidentSet
                                       .Where(c => c.CaseTypeCode == targetType &&
                                              c.Title == caseTitle)
                                       //&& accountIds.Contains(c.CustomerId.Id.ToString()))
                                       .Select(c => new CaseRetreiveModel
                    {
                        Id           = c.IncidentId.ToString(),
                        CaseCustomer = c.CustomerId.Id.ToString(),
                        Title        = c.Title
                    })
                                       .ToList();
                    log.Info($"Cases retrieved {casesToSolve.Count}");

                    //Check if those casese belongs to Accounts in input
                    //This is something that I donot understand in previous query if uncomment every time there is exception for invalid Where condition
                    // Below the condition is EXACTLY the same and works perfectly
                    casesToSolve = casesToSolve
                                   .Where(x => accountIds.Contains(x.CaseCustomer))
                                   .ToList();

                    log.Info($"Cases filtered with input customer Ids {casesToSolve.Count}");

                    return(casesToSolve);
                }
            }
            catch (Exception ex)
            {
                log.Error($"{nameof(AllActiveByTypeAndAccountId)} throws exception: {ex.Message}");
                Console.WriteLine(ex.Message);

                return(Enumerable.Empty <CaseRetreiveModel>());
            }
        }
Пример #4
0
        public bool SentRegistrationReport(IEnumerable <string> reportingEmails, IEnumerable <string> successfulOperations, IEnumerable <string> failedOperations)
        {
            log.Info($"{nameof(SentRegistrationReport)} Started");
            try
            {
                using (var context = crmConnection.GetContext())
                {
                    //Success TABLE Creation
                    string successTable = SUCCESS_REPORT_HEAD;
                    successTable = SplitLine(successfulOperations, successTable);

                    //Fail TABLE Creation
                    string failTable = FAIL_REPORT_HEAD;
                    failTable = SplitLine(failedOperations, failTable);


                    //Forming TO party
                    //EntityCollection toActivityParty = new EntityCollection();
                    var toActivityParty = new List <ActivityParty>();
                    foreach (var currentEmail in reportingEmails)
                    {
                        var partyTosentMail = new ActivityParty();
                        partyTosentMail.AddressUsed = currentEmail;

                        toActivityParty.Add(partyTosentMail);
                    }

                    //Form FROM party
                    var fromActivityParty = new ActivityParty();
                    fromActivityParty.PartyId     = new EntityReference("systemuser", crmConnection.GetUserId);
                    fromActivityParty.AddressUsed = "*****@*****.**";

                    //Sent Email
                    var email = new Email();
                    email.From = new List <ActivityParty>()
                    {
                        fromActivityParty
                    };
                    email.To          = toActivityParty;
                    email.Subject     = "Report on Request task Id:";
                    email.Description = $"Dear Colleagues, " +
                                        $"{Environment.NewLine} " +
                                        $"Registrations updated: {successfulOperations.Count()} " +
                                        $"{Environment.NewLine} " +
                                        $"{successTable} " +
                                        $"{Environment.NewLine}{Environment.NewLine} " +
                                        $"Issues found: {failedOperations.Count()} " +
                                        $"{Environment.NewLine} {Environment.NewLine} " +
                                        $"{failTable} " +
                                        $"{Environment.NewLine} " +
                                        $"Yeahhhhh, UGLY but sent !!";
                    email.DirectionCode = true;

                    Guid emailId = crmConnection.Service.Create(email);
                    if (emailId == Guid.Empty)
                    {
                        log.Error("Reporting email was NOT created sucessfully");
                        return(false);
                    }
                    else
                    {
                        log.Info("Reporting email created sucessfully");
                    }

                    SendEmailRequest sendEmailRequest = new SendEmailRequest
                    {
                        EmailId       = emailId,
                        TrackingToken = "",
                        IssueSend     = true
                    };

                    SendEmailResponse sendEmailresp = (SendEmailResponse)crmConnection.Service.Execute(sendEmailRequest);
                    log.Info("Report email sent sucessfully");

                    return(true);
                }
            }
            catch (Exception ex)
            {
                log.Error($"{nameof(SentRegistrationReport)} throws exception: {ex.Message}");
                Console.WriteLine(ex.Message);

                return(false);
            }
        }