Ejemplo n.º 1
0
        public bool SendEmailForAction(ActionTabEmail item, Guid ClientId)
        {
            try
            {
                UserLoginRole UL      = new UserLoginRole();
                string        BaseUrl = "";
                List <fn_getClientResourceData_Result> EmailDetails = UL.GetResourceEmailDetails(ClientId, "Email Configuration");
                foreach (fn_getClientResourceData_Result Email in EmailDetails)
                {
                    if (Email.Name == "SocketLabsServerId")
                    {
                        item.ServerId = Email.Value;
                    }

                    if (Email.Name == "SocketLabsUrl")
                    {
                        BaseUrl = Email.Value;
                    }

                    if (Email.Name == "SocketLabsApiKey")
                    {
                        item.ApiKey = Email.Value;
                    }

                    if (Email.Name == "APITemplateKey")
                    {
                        item.Messages[0].ApiTemplate = Email.Value;
                    }

                    if (Email.Name == "EmailDefaultFrom")
                    {
                        item.Messages[0].From = new FromFields();
                        item.Messages[0].From.EmailAddress = Email.Value;
                        item.Messages[0].From.FriendlyName = "";
                    }
                }


                string EmailData = JsonConvert.SerializeObject(item);
                var    client    = new RestClient(BaseUrl);
                var    request   = new RestRequest(Method.POST);
                request.AddParameter("application/json", EmailData, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);

                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("content-type", "application/json");
                request.AddHeader("accept", "application/json");

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public string SendEmailtoVendor(ActionTabEmailOld item)
        {
            try
            {
                ActionTabEmail actionTabEmail = new ActionTabEmail();

                //1. ) Adding "to" Fields in Message Fields.
                ToFields toFields = new ToFields();
                toFields.EmailAddress = "%%DeliveryAddress%%";
                toFields.FriendlyName = "";

                List <ToFields> toFieldsList = new List <ToFields>();
                toFieldsList.Add(toFields);
                MessagesFields messagesFields = new MessagesFields();
                messagesFields.To = toFieldsList;


                List <string> emailAddresses = new List <string>();
                emailAddresses.Add(item.Toemail);

                //2.) Adding CC Fields in Message Fields.
                List <CcFields> ccFieldsList = new List <CcFields>();
                if (item.Ccemail != null)
                {
                    foreach (string ccItem in item.Ccemail)
                    {
                        CcFields ccFields = new CcFields();
                        // ccFields.EmailAddress = "%%CcEmail1%%";
                        ccFields.EmailAddress = "%%DeliveryAddress%%";
                        ccFields.FriendlyName = "";
                        ccFieldsList.Add(ccFields);

                        emailAddresses.Add(ccItem);
                    }
                    messagesFields.Cc = ccFieldsList;
                }

                // Adding Work Order Attachment for sending email.
                string FileName      = null;
                string temp_inBase64 = null;
                List <AttachmentsDocuments> DocsFile = new List <AttachmentsDocuments>();
                if (item.ChekValue == true)
                {
                    byte[] EmailPDFData = repository.GetPDFDataWith(item.WorkOrderId);
                    temp_inBase64 = Convert.ToBase64String(EmailPDFData);
                    FileName      = "WO_" + item.WorkOrderNumber + ".pdf";

                    AttachmentsDocuments docs = new AttachmentsDocuments();
                    docs.Name    = FileName;
                    docs.Content = temp_inBase64;
                    DocsFile.Add(docs);
                }

                // Adding Other Document for sending email.
                if (item.OtherDocument != null)
                {
                    foreach (var value in item.OtherDocument)
                    {
                        List <Tuple <byte[], string> > DocsData = repository.GetAttachmentData(value);
                        FileName      = DocsData[0].Item2;
                        temp_inBase64 = Convert.ToBase64String(DocsData[0].Item1);

                        AttachmentsDocuments docs = new AttachmentsDocuments();
                        docs.Name    = FileName;
                        docs.Content = temp_inBase64;
                        DocsFile.Add(docs);
                    }
                }

                // Getting data for dynamic values on Email Template
                List <EmailData> EmailData = GetEmailData(item.WorkOrderId);
                List <fn_getClientResourceData_Result> HeaderData = repository.DataforPDfHeader(item.ClientId);
                List <List <PerMessage> > perMessagesArrayList    = new List <List <PerMessage> >();

                MergedData mergedData = new MergedData();
                foreach (string e in emailAddresses)
                {
                    List <PerMessage> perMessagesList = new List <PerMessage>();

                    PerMessage perMessageDeliveryAddress = new PerMessage();
                    perMessageDeliveryAddress.Field = "DeliveryAddress";
                    perMessageDeliveryAddress.Value = e;
                    PerMessage perMessageVendorName = new PerMessage();
                    perMessageVendorName.Field = "VendorName";
                    perMessageVendorName.Value = EmailData[0].VendorName;

                    PerMessage perMessageCSRName = new PerMessage();
                    perMessageCSRName.Field = "CSRName";
                    perMessageCSRName.Value = EmailData[0].FirstName + " " + EmailData[0].LastName;

                    PerMessage perMessageCompanyName = new PerMessage();
                    perMessageCompanyName.Field = "CompanyName";
                    perMessageCompanyName.Value = EmailData[0].ClientName;

                    PerMessage perMessageCompanyName2 = new PerMessage();
                    perMessageCompanyName2.Field = "CompanyName2";
                    perMessageCompanyName2.Value = EmailData[0].ClientName;

                    PerMessage perMessageAddress01 = new PerMessage();;
                    PerMessage perMessageAddress02 = new PerMessage();
                    PerMessage perMessageTelephone = new PerMessage();
                    PerMessage perMessageFax       = new PerMessage();
                    PerMessage perMessageURL       = new PerMessage();

                    foreach (fn_getClientResourceData_Result headerData in HeaderData)
                    {
                        if (headerData.Name == "WOHeaderLine01")
                        {
                            perMessageAddress01.Field = "Address01";
                            perMessageAddress01.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine02")
                        {
                            perMessageAddress02.Field = "Address02";
                            perMessageAddress02.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine03")
                        {
                            perMessageTelephone.Field = "Telephone";
                            perMessageTelephone.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine04")
                        {
                            perMessageFax.Field = "Fax";
                            perMessageFax.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine05")
                        {
                            perMessageURL.Field = "URL";
                            perMessageURL.Value = headerData.Value;
                        }
                    }
                    PerMessage perMessageMessage = new PerMessage();
                    perMessageMessage.Field = "Message";
                    perMessageMessage.Value = item.Message;



                    perMessagesList.Add(perMessageDeliveryAddress);
                    perMessagesList.Add(perMessageVendorName);
                    perMessagesList.Add(perMessageCSRName);
                    perMessagesList.Add(perMessageCompanyName);
                    perMessagesList.Add(perMessageCompanyName2);
                    perMessagesList.Add(perMessageAddress01);
                    perMessagesList.Add(perMessageAddress02);
                    perMessagesList.Add(perMessageTelephone);
                    perMessagesList.Add(perMessageFax);
                    perMessagesList.Add(perMessageURL);
                    perMessagesList.Add(perMessageMessage);

                    perMessagesArrayList.Add(perMessagesList);

                    mergedData.PerMessage = perMessagesArrayList;
                }

                messagesFields.MergeData   = mergedData;
                messagesFields.Attachments = DocsFile;
                messagesFields.Subject     = item.WorkOrderNumber;

                // To add everything in the Message Fields
                List <MessagesFields> messagesFieldsList = new List <MessagesFields>();
                messagesFieldsList.Add(messagesFields);
                actionTabEmail.Messages = messagesFieldsList;

                string Updatevalue = repository.SendEmailtoVendor(item.WorkOrderId, FileName, item.Notes);
                new EmailController().SendEmail(actionTabEmail, item.ClientId);
                return(Updatevalue);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Message: " + ex.Message);
                return(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public bool SendEmailForNewCustomerUsers(EmailEntity Email)
        {
            try
            {
                ActionTabEmail actionTabEmail = new ActionTabEmail();
                //1. ) Adding "to" Fields in Message Fields.
                ToFields toFields = new ToFields();
                toFields.EmailAddress = "%%DeliveryAddress%%";
                toFields.FriendlyName = "";

                List <ToFields> toFieldsList = new List <ToFields>();
                toFieldsList.Add(toFields);
                MessagesFields messagesFields = new MessagesFields();
                messagesFields.To = toFieldsList;


                List <string> emailAddresses = new List <string>();
                emailAddresses.Add(Email.ToAddress);

                List <EmailDataForQuoteInvoice>  EmailData           = GetEmailDataforUser(Email.UserId, Email.IsClientVendorOrCustomer);
                List <EmailDataForClientDetails> EmailDataforClients = GetEmailDataforClientDetails(Email.LoggedInUserId);

                UOWWorkOrder uOWWorkOrder = new UOWWorkOrder();
                List <fn_getClientResourceData_Result> HeaderData = uOWWorkOrder.DataforPDfHeader(Email.ClientId);
                List <List <PerMessage> > perMessagesArrayList    = new List <List <PerMessage> >();

                MergedData mergedData = new MergedData();
                foreach (string e in emailAddresses)
                {
                    List <PerMessage> perMessagesList = new List <PerMessage>();

                    PerMessage perMessageDeliveryAddress = new PerMessage();
                    perMessageDeliveryAddress.Field = "DeliveryAddress";
                    perMessageDeliveryAddress.Value = e;

                    PerMessage perMessageVendorName = new PerMessage();
                    perMessageVendorName.Field = "VendorName";
                    perMessageVendorName.Value = EmailData[0].FirstName;

                    PerMessage perMessageCSRName = new PerMessage();
                    perMessageCSRName.Field = "CSRName";
                    perMessageCSRName.Value = EmailDataforClients[0].FirstName + " " + EmailDataforClients[0].LastName;

                    PerMessage perMessageCompanyName = new PerMessage();
                    perMessageCompanyName.Field = "CompanyName";
                    perMessageCompanyName.Value = EmailDataforClients[0].ClientName;

                    PerMessage perMessageCompanyName2 = new PerMessage();
                    perMessageCompanyName2.Field = "CompanyName2";
                    perMessageCompanyName2.Value = EmailDataforClients[0].ClientName;

                    PerMessage perMessageAddress01 = new PerMessage();;
                    PerMessage perMessageAddress02 = new PerMessage();
                    PerMessage perMessageTelephone = new PerMessage();
                    PerMessage perMessageFax       = new PerMessage();
                    PerMessage perMessageURL       = new PerMessage();

                    foreach (fn_getClientResourceData_Result headerData in HeaderData)
                    {
                        if (headerData.Name == "WOHeaderLine01")
                        {
                            perMessageAddress01.Field = "Address01";
                            perMessageAddress01.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine02")
                        {
                            perMessageAddress02.Field = "Address02";
                            perMessageAddress02.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine03")
                        {
                            perMessageTelephone.Field = "Telephone";
                            perMessageTelephone.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine04")
                        {
                            perMessageFax.Field = "Fax";
                            perMessageFax.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine05")
                        {
                            perMessageURL.Field = "URL";
                            perMessageURL.Value = headerData.Value;
                        }
                    }
                    PerMessage perMessageMessage = new PerMessage();
                    perMessageMessage.Field = "Message";
                    perMessageMessage.Value = Email.Body;



                    perMessagesList.Add(perMessageDeliveryAddress);
                    perMessagesList.Add(perMessageVendorName);
                    perMessagesList.Add(perMessageCSRName);
                    perMessagesList.Add(perMessageCompanyName);
                    perMessagesList.Add(perMessageCompanyName2);
                    perMessagesList.Add(perMessageAddress01);
                    perMessagesList.Add(perMessageAddress02);
                    perMessagesList.Add(perMessageTelephone);
                    perMessagesList.Add(perMessageFax);
                    perMessagesList.Add(perMessageURL);
                    perMessagesList.Add(perMessageMessage);

                    perMessagesArrayList.Add(perMessagesList);
                    mergedData.PerMessage = perMessagesArrayList;
                }

                messagesFields.MergeData = mergedData;
                // messagesFields.Attachments = DocsFile;
                messagesFields.Subject = Email.Subject;

                List <MessagesFields> messagesFieldsList = new List <MessagesFields>();
                messagesFieldsList.Add(messagesFields);
                actionTabEmail.Messages = messagesFieldsList;

                UserLoginRole UL      = new UserLoginRole();
                string        BaseUrl = "";
                List <fn_getClientResourceData_Result> EmailDetails = UL.GetResourceEmailDetails(Email.ClientId, "Email Configuration");
                foreach (fn_getClientResourceData_Result Email1 in EmailDetails)
                {
                    if (Email1.Name == "SocketLabsUrl")
                    {
                        BaseUrl = Email1.Value;
                    }
                    else if (Email1.Name == "SocketLabsServerId")
                    {
                        actionTabEmail.ServerId = Email1.Value;
                    }
                    else if (Email1.Name == "EmailDefaultFrom")
                    {
                        actionTabEmail.Messages[0].From = new FromFields();
                        actionTabEmail.Messages[0].From.EmailAddress = Email1.Value;
                        actionTabEmail.Messages[0].From.FriendlyName = "";
                    }
                    else if (Email1.Name == "SocketLabsApiKey")
                    {
                        actionTabEmail.ApiKey = Email1.Value;
                    }
                    else if (Email1.Name == "APITemplateKey")
                    {
                        actionTabEmail.Messages[0].ApiTemplate = Email1.Value;
                    }
                }

                string EmailDataFinal = JsonConvert.SerializeObject(actionTabEmail);
                var    client         = new RestClient(BaseUrl);
                var    request        = new RestRequest(Method.POST);
                request.AddParameter("application/json", EmailDataFinal, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);

                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("content-type", "application/json");
                request.AddHeader("accept", "application/json");

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public bool SubmitQuoteWithEmail(ServiceRequestInvoiceAction1 item)
        {
            try
            {
                ActionTabEmail actionTabEmail = new ActionTabEmail();

                //1. ) Adding "to" Fields in Message Fields.
                ToFields toFields = new ToFields();
                toFields.EmailAddress = "%%DeliveryAddress%%";
                toFields.FriendlyName = "";

                List <ToFields> toFieldsList = new List <ToFields>();
                toFieldsList.Add(toFields);
                MessagesFields messagesFields = new MessagesFields();
                messagesFields.To = toFieldsList;


                List <string> emailAddresses = new List <string>();
                emailAddresses.Add(item.Toemail);

                //2.) Adding CC Fields in Message Fields.
                List <CcFields> ccFieldsList = new List <CcFields>();
                foreach (string ccItem in item.Ccemail)
                {
                    CcFields ccFields = new CcFields();
                    ccFields.EmailAddress = "%%DeliveryAddress%%";
                    ccFields.FriendlyName = "";
                    ccFieldsList.Add(ccFields);

                    emailAddresses.Add(ccItem);
                }
                messagesFields.Cc = ccFieldsList;

                string FileName      = null;
                string temp_inBase64 = null;
                List <AttachmentsDocuments> DocsFile = new List <AttachmentsDocuments>();

                var UpdatedValue = repository.SubmitQuoteWithEmail(item);


                byte[] EmailPDFData = repository.GetServiceInvoicePDFData(item.ServiceRequestInvoiceHeaderId);
                temp_inBase64 = Convert.ToBase64String(EmailPDFData);
                FileName      = "Quote" + ".pdf";
                AttachmentsDocuments docs = new AttachmentsDocuments();
                docs.Name    = FileName;
                docs.Content = temp_inBase64;
                DocsFile.Add(docs);

                // Getting data for dynamic values on Email Template
                List <EmailDataForQuoteInvoice> EmailData = GetEmailData(item.ServiceRequestInvoiceHeaderId);
                UOWWorkOrder uOWWorkOrder = new UOWWorkOrder();
                List <fn_getClientResourceData_Result> HeaderData = uOWWorkOrder.DataforPDfHeader(item.ClientId);
                List <List <PerMessage> > perMessagesArrayList    = new List <List <PerMessage> >();

                MergedData mergedData = new MergedData();
                foreach (string e in emailAddresses)
                {
                    List <PerMessage> perMessagesList = new List <PerMessage>();

                    PerMessage perMessageDeliveryAddress = new PerMessage();
                    perMessageDeliveryAddress.Field = "DeliveryAddress";
                    perMessageDeliveryAddress.Value = e;

                    PerMessage perMessageVendorName = new PerMessage();
                    perMessageVendorName.Field = "VendorName";
                    perMessageVendorName.Value = EmailData[0].CustomerName;

                    PerMessage perMessageCSRName = new PerMessage();
                    perMessageCSRName.Field = "CSRName";
                    perMessageCSRName.Value = EmailData[0].FirstName + " " + EmailData[0].LastName;

                    PerMessage perMessageCompanyName = new PerMessage();
                    perMessageCompanyName.Field = "CompanyName";
                    perMessageCompanyName.Value = EmailData[0].ClientName;

                    PerMessage perMessageCompanyName2 = new PerMessage();
                    perMessageCompanyName2.Field = "CompanyName2";
                    perMessageCompanyName2.Value = EmailData[0].ClientName;

                    PerMessage perMessageAddress01 = new PerMessage();;
                    PerMessage perMessageAddress02 = new PerMessage();
                    PerMessage perMessageTelephone = new PerMessage();
                    PerMessage perMessageFax       = new PerMessage();
                    PerMessage perMessageURL       = new PerMessage();

                    foreach (fn_getClientResourceData_Result headerData in HeaderData)
                    {
                        if (headerData.Name == "WOHeaderLine01")
                        {
                            perMessageAddress01.Field = "Address01";
                            perMessageAddress01.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine02")
                        {
                            perMessageAddress02.Field = "Address02";
                            perMessageAddress02.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine03")
                        {
                            perMessageTelephone.Field = "Telephone";
                            perMessageTelephone.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine04")
                        {
                            perMessageFax.Field = "Fax";
                            perMessageFax.Value = headerData.Value;
                        }
                        if (headerData.Name == "WOHeaderLine05")
                        {
                            perMessageURL.Field = "URL";
                            perMessageURL.Value = headerData.Value;
                        }
                    }
                    PerMessage perMessageMessage = new PerMessage();
                    perMessageMessage.Field = "Message";
                    perMessageMessage.Value = item.Message;
                    perMessagesList.Add(perMessageDeliveryAddress);
                    perMessagesList.Add(perMessageVendorName);
                    perMessagesList.Add(perMessageCSRName);
                    perMessagesList.Add(perMessageCompanyName);
                    perMessagesList.Add(perMessageCompanyName2);
                    perMessagesList.Add(perMessageAddress01);
                    perMessagesList.Add(perMessageAddress02);
                    perMessagesList.Add(perMessageTelephone);
                    perMessagesList.Add(perMessageFax);
                    perMessagesList.Add(perMessageURL);
                    perMessagesList.Add(perMessageMessage);
                    perMessagesArrayList.Add(perMessagesList);
                    mergedData.PerMessage = perMessagesArrayList;
                }

                messagesFields.MergeData   = mergedData;
                messagesFields.Attachments = DocsFile;
                messagesFields.Subject     = item.ActionCode;

                // To add everything in the Message Fields
                List <MessagesFields> messagesFieldsList = new List <MessagesFields>();
                messagesFieldsList.Add(messagesFields);
                actionTabEmail.Messages = messagesFieldsList;

                if (UpdatedValue == true)
                {
                    new EmailController().SendEmailToCustomer(actionTabEmail, item.ClientId);
                }

                return(UpdatedValue);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }