public virtual void CreateMessageContentAttachement(MessageContentAttachement messageContentAttachement)
 {
     try
     {
         Database database = DatabaseFactory.CreateDatabase("CustommerServiceConnection");
         DbCommand dbCommand = database.GetStoredProcCommand("spMessageContentAttachementInsert");
         
         database.AddInParameter(dbCommand, "@AttachementDocument", DbType.String, messageContentAttachement.AttachementDocument);
         database.AddInParameter(dbCommand, "@AttachementDescription", DbType.String, messageContentAttachement.AttachementDescription);
         database.AddInParameter(dbCommand, "@MessageContentID", DbType.Int32, messageContentAttachement.MessageContentID);
         database.AddInParameter(dbCommand, "@CreatedDate", DbType.DateTime, messageContentAttachement.CreatedDate);
         database.AddInParameter(dbCommand, "@ModifiedDate", DbType.DateTime, messageContentAttachement.ModifiedDate);
         database.AddOutParameter(dbCommand, "@MessageContentAttachementID", DbType.Int32, 0);
         
         database.ExecuteNonQuery(dbCommand);
         messageContentAttachement.MessageContentAttachementID = (int)database.GetParameterValue(dbCommand, "@MessageContentAttachementID");
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.DataAccessCreateMessageContentAttachementException, ex);
     }
 }
 public static void UpdateMessageContentAttachement(MessageContentAttachement messageContentAttachement)
 {            
     try
     {
         MessageContentAttachementDAO messageContentAttachementDAO = new MessageContentAttachementDAO();
         messageContentAttachementDAO.UpdateMessageContentAttachement(messageContentAttachement);
     }
     catch (ApplicationException)
     {
         throw;
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.BusinessUpdateMessageContentAttachementException, ex);
     }
 }        
 public virtual MessageContentAttachement CreateMessageContentAttachementFromReader(IDataReader reader)
 {
     MessageContentAttachement item = new MessageContentAttachement();
     try
     {
         if (!reader.IsDBNull(reader.GetOrdinal("MessageContentAttachementID"))) item.MessageContentAttachementID = (int)reader["MessageContentAttachementID"];
         if (!reader.IsDBNull(reader.GetOrdinal("AttachementDocument"))) item.AttachementDocument = (string)reader["AttachementDocument"];
         if (!reader.IsDBNull(reader.GetOrdinal("AttachementDescription"))) item.AttachementDescription = (string)reader["AttachementDescription"];
         if (!reader.IsDBNull(reader.GetOrdinal("MessageContentID"))) item.MessageContentID = (int)reader["MessageContentID"];
         if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) item.CreatedDate = (DateTime)reader["CreatedDate"];
         if (!reader.IsDBNull(reader.GetOrdinal("ModifiedDate"))) item.ModifiedDate = (DateTime)reader["ModifiedDate"];
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.DataAccessCreateMessageContentAttachementFromReaderException, ex);
     }
     return item;
 }
Example #4
0
        public static void CreateMessageWhenNewCustomer(Customer customer, ContentTemplate contentTemplate, string MorE)
        {
            MessageContent messageContent = null;
            messageContent = new MessageContent();
            messageContent.Sender = contentTemplate.Sender;
            if(MorE == "M")
                messageContent.Receiver = customer.Mobile;
            else
                messageContent.Receiver = customer.Email;
            messageContent.Subject = contentTemplate.Subject;
            messageContent.BodyContentType = contentTemplate.BodyContentType;
            messageContent.BodyEncoding = contentTemplate.BodyEncoding;
            messageContent.BodyMessage = contentTemplate.BodyMessage.Replace("#name#", customer.CustomerName).Replace("#customerid#", customer.CustomerId);
            messageContent.ContentTemplateID = contentTemplate.ContentTemplateID;
            messageContent.ServiceTypeID = contentTemplate.ServiceTypeID;
            messageContent.ModifiedDate = DateTime.Now;
            messageContent.CreatedDate = DateTime.Now;
            messageContent.Status = 0;

            MessageContentService.CreateMessageContent(messageContent);
            ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
            foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
            {
                MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                messageContentAttachement.ModifiedDate = DateTime.Now;
                messageContentAttachement.CreatedDate = DateTime.Now;
                MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
            }
        }
Example #5
0
        public static void CreateMessageWithEmail(Stream stream, string filePath, string fileName, ContentTemplate contentTemplate)
        {
            string[] typicalHeaders = {"Receiver"};
            string[] headers;
            List<string[]> data = null;
            try
            {
                string uploadFileName = UploadService.UploadDocument(stream, filePath, fileName);
                ReadCvsData(filePath + uploadFileName, out headers, out data);

                if (!ValidateHeaders(typicalHeaders, headers))
                {
                    throw new InvalidDataException("CSV file is invalid format!");
                }

                foreach (string[] items in data)
                {

                    //shareHolder.ShareHolderCode = items[0];
                    MessageContent messageContent = null;
                    messageContent = new MessageContent();
                    messageContent.Sender = contentTemplate.Sender;
                    
                    messageContent.Receiver = items[0];
                    messageContent.Subject = contentTemplate.Subject;
                    messageContent.BodyContentType = contentTemplate.BodyContentType;
                    messageContent.BodyEncoding = contentTemplate.BodyEncoding;
                    messageContent.BodyMessage   = contentTemplate.BodyMessage;
                    messageContent.ContentTemplateID   = contentTemplate.ContentTemplateID;
                    messageContent.ServiceTypeID   = contentTemplate.ServiceTypeID;
                    messageContent.ModifiedDate   = DateTime.Now;
                    messageContent.CreatedDate   = DateTime.Now;
                    messageContent.Status   = 0;

                    MessageContentService.CreateMessageContent(messageContent);
                    ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                    foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)    
                    {
                        MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                        messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                        messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                        messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                        messageContentAttachement.ModifiedDate   = DateTime.Now;
                        messageContentAttachement.CreatedDate   = DateTime.Now;
                        MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                    }
                }
                if (File.Exists(filePath + uploadFileName))
                {
                    File.Delete(filePath + uploadFileName);
                }
            }

            catch (Exception ex)
            {
                // log this exception
                log4net.Util.LogLog.Error(ex.Message, ex);
                // wrap it and rethrow
                throw new ApplicationException(SR.BusinessImport_CreateMessageWithEmailException, ex);
            }

            finally
            {
                if (data != null) data = null;
            }
        }
Example #6
0
        public static void CreateMessageWithEmailEncrypt(string[] data, ContentTemplate contentTemplate, ref int numberCustomerSent)
        {
            SimpleAES encryptEmail = new SimpleAES();

            foreach (string item in data)
            {
                //shareHolder.ShareHolderCode = items[0];
                if (item != string.Empty && item != null)
                {
                    numberCustomerSent++;
                    MessageContent messageContent = null;
                    messageContent = new MessageContent();
                    messageContent.Sender = contentTemplate.Sender;
                    messageContent.Receiver = item;
                    messageContent.Subject = contentTemplate.Subject;
                    messageContent.BodyContentType = contentTemplate.BodyContentType;
                    messageContent.BodyEncoding = contentTemplate.BodyEncoding;
                    messageContent.BodyMessage = contentTemplate.BodyMessage.Replace("$#email#", encryptEmail.EncryptToString(item));
                    messageContent.ContentTemplateID = contentTemplate.ContentTemplateID;
                    messageContent.ServiceTypeID = contentTemplate.ServiceTypeID;
                    messageContent.ModifiedDate = DateTime.Now;
                    messageContent.CreatedDate = DateTime.Now;
                    messageContent.Status = 0;

                    MessageContentService.CreateMessageContent(messageContent);
                    ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                    foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                    {
                        MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                        messageContentAttachement.AttachementDescription = attachement.AttachementDescription;                                                                                       
                        messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                        messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                        messageContentAttachement.ModifiedDate = DateTime.Now;
                        messageContentAttachement.CreatedDate = DateTime.Now;
                        MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                    }
                }
            }
        }
Example #7
0
        public static void CreateMessage(Customer cust, string contentToBeSent, string contentToBeSentSms, ContentTemplate contentTemplate, ContentTemplate contentTemplateSms)
        {
            if (cust != null)
            {
                SimpleAES encryptEmail = new SimpleAES();
                MessageContent messageContent = null;
                messageContent = new MessageContent();
                messageContent.Sender = contentTemplate.Sender;
                messageContent.Subject = contentTemplate.Subject;
                messageContent.BodyContentType = contentTemplate.BodyContentType;
                messageContent.BodyEncoding = contentTemplate.BodyEncoding;
                messageContent.BodyMessage = ReplaceBodyMessage(contentTemplate.BodyMessage, contentToBeSent);                
                messageContent.ContentTemplateID = contentTemplate.ContentTemplateID;
                messageContent.ServiceTypeID = contentTemplate.ServiceTypeID;
                messageContent.ModifiedDate = DateTime.Now;
                messageContent.CreatedDate = DateTime.Now;
                messageContent.Status = 0;
                //in case the message is type of email check if the email address is valid
                if (cust.ReceiveRelatedStockEmail.Trim() == "Y")
                {
                    messageContent.Receiver = cust.Email;
                    messageContent.BodyMessage = messageContent.BodyMessage.Replace("$#email#", encryptEmail.EncryptToString(cust.Email));
                    if (ValidateEmail(messageContent.Receiver) == true)
                    {
                        MessageContentService.CreateMessageContent(messageContent);
                        ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                        foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                        {
                            MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                            messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                            messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                            messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                            messageContentAttachement.ModifiedDate = DateTime.Now;
                            messageContentAttachement.CreatedDate = DateTime.Now;
                            MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                        }
                    }
                }

                if (cust.ReceiveRelatedStockSms.Trim() == "Y")
                {
                    messageContent = null;
                    messageContent = new MessageContent();
                    messageContent.Sender = contentTemplateSms.Sender;
                    messageContent.Subject = contentTemplateSms.Subject;
                    messageContent.BodyContentType = contentTemplateSms.BodyContentType;
                    messageContent.BodyEncoding = contentTemplateSms.BodyEncoding;
                    messageContent.BodyMessage = ReplaceBodyMessage(contentTemplateSms.BodyMessage, contentToBeSentSms);
                    messageContent.ContentTemplateID = contentTemplateSms.ContentTemplateID;
                    messageContent.ServiceTypeID = contentTemplateSms.ServiceTypeID;
                    messageContent.ModifiedDate = DateTime.Now;
                    messageContent.CreatedDate = DateTime.Now;
                    messageContent.Status = 0;
                    messageContent.Receiver = cust.Mobile;
                    MessageContentService.CreateMessageContent(messageContent);
                    ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplateSms.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                    foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                    {
                        MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                        messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                        messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                        messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                        messageContentAttachement.ModifiedDate = DateTime.Now;
                        messageContentAttachement.CreatedDate = DateTime.Now;
                        MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                    }
                }
            }
        }
Example #8
0
 public static void CreateMessage(CustomerCollection data, string[] contentToBeSent, ContentTemplate contentTemplate, ref int numberCustomerSent)
 {
     int i = 0;
     foreach (Customer item in data)
     {
         //shareHolder.ShareHolderCode = items[0];
         if (item != null)
         {
             numberCustomerSent++;
             MessageContent messageContent = null;
             messageContent = new MessageContent();
             messageContent.Sender = contentTemplate.Sender;                    
             messageContent.Subject = contentTemplate.Subject;
             messageContent.BodyContentType = contentTemplate.BodyContentType;
             messageContent.BodyEncoding = contentTemplate.BodyEncoding;
             messageContent.BodyMessage = ReplaceBodyMessage(contentTemplate.BodyMessage, contentToBeSent[i++]);
             messageContent.ContentTemplateID = contentTemplate.ContentTemplateID;
             messageContent.ServiceTypeID = contentTemplate.ServiceTypeID;
             messageContent.ModifiedDate = DateTime.Now;
             messageContent.CreatedDate = DateTime.Now;
             messageContent.Status = 0;
             //in case the message is type of email check if the email address is valid
             if (messageContent.ServiceTypeID == 1)
             {
                 messageContent.Receiver = item.Email;
                 if (ValidateEmail(messageContent.Receiver) == true)
                 {
                     MessageContentService.CreateMessageContent(messageContent);
                     ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                     foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                     {
                         MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                         messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                         messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                         messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                         messageContentAttachement.ModifiedDate = DateTime.Now;
                         messageContentAttachement.CreatedDate = DateTime.Now;
                         MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                     }
                 }
             }
             else
             {
                 messageContent.Receiver = item.Mobile;
                 MessageContentService.CreateMessageContent(messageContent);
                 ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                 foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                 {
                     MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                     messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                     messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                     messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                     messageContentAttachement.ModifiedDate = DateTime.Now;
                     messageContentAttachement.CreatedDate = DateTime.Now;
                     MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                 }
             }
         }
     }
 }
Example #9
0
        public static void CreateMessage(string filePath, string fileName, ContentTemplate contentTemplate, NameValueCollection parameters, out Int32 successCount, out List<string[]> notImportedData)
        {
            string[] typicalHeaders = null;
            string[] headers ;
            List<string[]> data = null;
            Hashtable hastableParameters = new Hashtable();
            notImportedData = new List<string[]>();
            successCount = 0;
            try
            {                
                ReadCvsHeader(filePath + fileName, out headers);          
                ReadCvsData(filePath + fileName, out headers, out data);

                if (!ValidateHeaders(typicalHeaders, headers))
                {
                    throw new InvalidDataException("CSV file is invalid format!");
                }

                foreach (string[] items in data)
                {
                    //shareHolder.ShareHolderCode = items[0];
                    MessageContent messageContent = null;
                    messageContent = new MessageContent();
                    messageContent.Sender = contentTemplate.Sender;
                    Customer customer = null;
                    string customerId = items[0].Replace("K", "C");
                    customer = CustomerService.GetCustomer(customerId);

                    if (customer == null)
                    {
                        notImportedData.Add(items);
                    }
                    else
                    {
                        if (contentTemplate.ServiceTypeID == 1)
                            messageContent.Receiver = customer.Email;
                        else
                            messageContent.Receiver = customer.Mobile;

                        messageContent.Subject = contentTemplate.Subject;
                        messageContent.BodyContentType = contentTemplate.BodyContentType;
                        messageContent.BodyEncoding = contentTemplate.BodyEncoding;
                        hastableParameters = ConvertParametersToHastable(parameters);                                              
                        messageContent.BodyMessage = ReplaceBodyMessage(contentTemplate.BodyMessage, hastableParameters, items);                                                
                        messageContent.ContentTemplateID = contentTemplate.ContentTemplateID;
                        messageContent.ServiceTypeID = contentTemplate.ServiceTypeID;
                        messageContent.ModifiedDate = DateTime.Now;
                        messageContent.CreatedDate = DateTime.Now;
                        messageContent.Status = 0;

                        if (contentTemplate.ServiceTypeID == 1)
                        {
                            if (ValidateEmail(messageContent.Receiver) == true)
                            {   
                                MessageContentService.CreateMessageContent(messageContent);
                                ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                                foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                                {
                                    MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                                    messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                                    messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                                    messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                                    messageContentAttachement.ModifiedDate = DateTime.Now;
                                    messageContentAttachement.CreatedDate = DateTime.Now;
                                    MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                                }
                                successCount++;
                            }
                        }
                        else
                        {
                            MessageContentService.CreateMessageContent(messageContent);
                            ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                            foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                            {
                                MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                                messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                                messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                                messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                                messageContentAttachement.ModifiedDate = DateTime.Now;
                                messageContentAttachement.CreatedDate = DateTime.Now;
                                MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                            }
                            successCount++;
                        }
                    }
                }
                if (File.Exists(filePath + fileName))
                {
                    File.Delete(filePath + fileName);
                }
            }

            catch (Exception ex)
            {
                // log this exception
                log4net.Util.LogLog.Error(ex.Message, ex);
                // wrap it and rethrow
                throw new ApplicationException(SR.BusinessImport_CreateMessageWithEmailException, ex);
            }

            finally
            {
                if (data != null) data = null;
            }
        }