public Email_Response send_email(string type, int booking_id, string email_ids, string cc_email_ids, string bcc_email_ids, string subject, string content_dict, string attachments_dict)
        {
            Email_Response response = new Email_Response();
            Email.Email email;
            Utils.clsLogger logger = new Utils.clsLogger();
            Dictionary<string, object> content = new Dictionary<string, object>();
            Dictionary<string, object> attachments = new Dictionary<string, object>();

            if (type == null || type.Trim().Length == 0)
            {
                type = "blank_email";
            }

            content = JsonConvert.DeserializeObject<Dictionary<string, object>>(content_dict);

            if (attachments_dict != null)
            {
                attachments = JsonConvert.DeserializeObject<Dictionary<string, object>>(attachments_dict);
            }

            string[] valid_email_types = ConfigurationManager.AppSettings["Valid_Email_Types"].ToString().Split(',');

            int success = 1;
            try
            {
                response.result.type = type;
                response.result.booking_id = booking_id;
                response.result.email_ids = email_ids;
                response.result.cc_email_ids = cc_email_ids;
                response.result.bcc_email_ids = bcc_email_ids;
                response.status = true;

                if(valid_email_types.Contains(type))
                {
                    email = new Email.Email(type, subject, content,attachments);
                    response.status = email.send_email(booking_id, email_ids, cc_email_ids, bcc_email_ids);
                }
                else
                {
                    throw new System.Exception("Invalid Email Type");
                }
            }
            catch (System.Exception ex)
            {
                success = 0;
                logger.log("error", new Dictionary<string, object>
                {   {"booking_id",booking_id},
                    {"email_ids",email_ids},
                    {"cc_email_ids",cc_email_ids},
                    {"bcc_email_ids",bcc_email_ids},
                    {"type",type}
                }, ex.ToString());
                response.status = false;
                response.error = ex.Message;
            }

            if (success == 1)
            {
                logger.log("info", new Dictionary<string, object>
                {   {"booking_id",booking_id},
                    {"email_ids",email_ids},
                    {"cc_email_ids",cc_email_ids},
                    {"bcc_email_ids",bcc_email_ids},
                    {"type",type}
                }, "success");
            }
            //Log email into db;
            //Email.Email.log_email_into_db(type, booking_id, response.result.email_ids, response.result.cc_email_ids, response.result.bcc_email_ids, response.error, Convert.ToInt32(response.status));
            return response;
        }
Esempio n. 2
0
        public Email_Response send_email(string type, int booking_id, string email_ids, string cc_email_ids, string bcc_email_ids, string subject, string content_dict, string attachments_dict)
        {
            Email_Response response = new Email_Response();

            Email.Email                 email;
            Utils.clsLogger             logger      = new Utils.clsLogger();
            Dictionary <string, object> content     = new Dictionary <string, object>();
            Dictionary <string, object> attachments = new Dictionary <string, object>();

            if (type == null || type.Trim().Length == 0)
            {
                type = "blank_email";
            }

            content = JsonConvert.DeserializeObject <Dictionary <string, object> >(content_dict);

            if (attachments_dict != null)
            {
                attachments = JsonConvert.DeserializeObject <Dictionary <string, object> >(attachments_dict);
            }

            string[] valid_email_types = ConfigurationManager.AppSettings["Valid_Email_Types"].ToString().Split(',');

            int success = 1;

            try
            {
                response.result.type          = type;
                response.result.booking_id    = booking_id;
                response.result.email_ids     = email_ids;
                response.result.cc_email_ids  = cc_email_ids;
                response.result.bcc_email_ids = bcc_email_ids;
                response.status = true;

                if (valid_email_types.Contains(type))
                {
                    email           = new Email.Email(type, subject, content, attachments);
                    response.status = email.send_email(booking_id, email_ids, cc_email_ids, bcc_email_ids);
                }
                else
                {
                    throw new System.Exception("Invalid Email Type");
                }
            }
            catch (System.Exception ex)
            {
                success = 0;
                logger.log("error", new Dictionary <string, object>
                {
                    { "booking_id", booking_id },
                    { "email_ids", email_ids },
                    { "cc_email_ids", cc_email_ids },
                    { "bcc_email_ids", bcc_email_ids },
                    { "type", type }
                }, ex.ToString());
                response.status = false;
                response.error  = ex.Message;
            }

            if (success == 1)
            {
                logger.log("info", new Dictionary <string, object>
                {
                    { "booking_id", booking_id },
                    { "email_ids", email_ids },
                    { "cc_email_ids", cc_email_ids },
                    { "bcc_email_ids", bcc_email_ids },
                    { "type", type }
                }, "success");
            }
            //Log email into db;
            //Email.Email.log_email_into_db(type, booking_id, response.result.email_ids, response.result.cc_email_ids, response.result.bcc_email_ids, response.error, Convert.ToInt32(response.status));
            return(response);
        }