Exemple #1
0
 public string BodyMessage(BodyMessageEntity bodyMessageEntity)
 {
     try
     {
         string messageBody        = "<font>Hi Team, </font><br><br>";
         string htmlTableStart     = "<table style=\"border-collapse:collapse; text-align:center;\" >";
         string htmlTableEnd       = "</table>";
         string htmlHeaderRowStart = "<tr style=\"background-color:#6FA1D2; color:#ffffff;\">";
         string htmlHeaderRowEnd   = "</tr>";
         string htmlTrStart        = "<tr style=\"color:#555555;\">";
         string htmlTrEnd          = "</tr>";
         string htmlTdStart        = "<td style=\" border-color:#5c87b2; border-style:solid; border-width:thin; padding: 5px;\">";
         string htmlTdEnd          = "</td>";
         messageBody += "Please provide the quotation for below mentioned products. <br><br>";
         messageBody += htmlTableStart;
         messageBody += htmlHeaderRowStart;
         messageBody += htmlTdStart + "Region" + htmlTdEnd;
         messageBody += htmlTdStart + "Godown" + htmlTdEnd;
         messageBody += htmlTdStart + "Email id" + htmlTdEnd;
         messageBody += htmlTdStart + "Phone Number" + htmlTdEnd;
         messageBody += htmlTdStart + "Products" + htmlTdEnd;
         messageBody += htmlTdStart + "Remarks" + htmlTdEnd;
         messageBody += htmlHeaderRowEnd;
         //Loop all the rows from grid vew and added to html td
         messageBody  = messageBody + htmlTrStart;
         messageBody += htmlTdStart + bodyMessageEntity.RName + htmlTdEnd;
         messageBody += htmlTdStart + bodyMessageEntity.GName + htmlTdEnd;
         messageBody += htmlTdStart + bodyMessageEntity.Mailid + htmlTdEnd;
         messageBody += htmlTdStart + bodyMessageEntity.PhoneNumber + htmlTdEnd;
         messageBody += htmlTdStart + bodyMessageEntity.Products + htmlTdEnd;
         messageBody += htmlTdStart + bodyMessageEntity.Remarks + htmlTdEnd;
         messageBody += htmlTrEnd + htmlTableEnd + "<br><br>";
         messageBody += "Thanks & Regads <br>";
         messageBody += " SI Support Team";
         return(messageBody);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
Exemple #2
0
        public Tuple <bool, string> Post(QuotationEntity entity)
        {
            string         QId      = string.Empty;
            SqlTransaction objTrans = null;

            using (sqlConnection = new SqlConnection(GlobalVariable.ConnectionString))
            {
                DataSet ds = new DataSet();

                sqlCommand = new SqlCommand();
                try
                {
                    if (sqlConnection.State == 0)
                    {
                        sqlConnection.Open();
                    }
                    objTrans               = sqlConnection.BeginTransaction();
                    sqlCommand             = new SqlCommand();
                    sqlCommand.Transaction = objTrans;
                    sqlCommand.Connection  = sqlConnection;
                    sqlCommand.CommandText = "InsertQuotationDetails";
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.AddWithValue("@EmailID", entity.EmailID);
                    sqlCommand.Parameters.AddWithValue("@PhoneNo", entity.PhoneNo);
                    sqlCommand.Parameters.AddWithValue("@Remarks", entity.Remarks);
                    sqlCommand.Parameters.AddWithValue("@GCode", entity.GCode);
                    sqlCommand.Parameters.AddWithValue("@RCode", entity.RCode);
                    sqlCommand.Parameters.Add("@Q_ID", SqlDbType.Int, 8);
                    sqlCommand.Parameters["@Q_ID"].Direction = ParameterDirection.Output;
                    sqlCommand.ExecuteNonQuery();

                    QId = Convert.ToString(sqlCommand.Parameters["@Q_ID"].Value);

                    foreach (var item in entity.ProductID)
                    {
                        sqlCommand.Parameters.Clear();
                        sqlCommand.Dispose();

                        sqlCommand             = new SqlCommand();
                        sqlCommand.Transaction = objTrans;
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandText = "InsertQuotationProductDeatils";
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.Parameters.AddWithValue("@Q_Id", QId);
                        sqlCommand.Parameters.AddWithValue("@P_Id", item);
                        sqlCommand.ExecuteNonQuery();
                    }
                    objTrans.Commit();
                    sqlCommand.Parameters.Clear();
                    sqlCommand.Dispose();

                    ///MailSending
                    ///sqlCommand = new SqlCommand();
                    sqlCommand.Transaction = objTrans;
                    sqlCommand.Connection  = sqlConnection;
                    sqlCommand.CommandText = "GetMailDetails";
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.ExecuteNonQuery();
                    SendMail          sendMail          = new SendMail();
                    BodyMessageEntity bodyMessageEntity = new BodyMessageEntity
                    {
                        Mailid      = entity.EmailID,
                        PhoneNumber = entity.PhoneNo,
                        Products    = entity.Products,
                        Remarks     = entity.Remarks,
                        RName       = entity.RNname,
                        GName       = entity.GName
                    };
                    using (SqlDataReader oReader = sqlCommand.ExecuteReader())
                    {
                        while (oReader.Read())
                        {
                            MailEntity mailEntity = new MailEntity
                            {
                                FromMailid   = oReader["FromMailId"].ToString(),
                                ToMailid     = oReader["ToId"].ToString(),
                                FromPassword = oReader["FromPassword"].ToString(),
                                ToCC         = oReader["ToCC"].ToString(),
                                SMTP         = oReader["Host"].ToString(),
                                Port         = Convert.ToInt16(oReader["Port"]),
                                Subject      = oReader["MailSubject"].ToString(),
                                BodyMessage  = sendMail.BodyMessage(bodyMessageEntity)
                            };
                            Task.Run(() => sendMail.MailSending(mailEntity));
                        }
                    }
                    objTrans.Commit();
                    sqlCommand.Parameters.Clear();
                    sqlCommand.Dispose();
                    return(new Tuple <bool, string>(true, GlobalVariable.SavedMessage));
                }
                catch (Exception ex)
                {
                    objTrans.Rollback();
                    AuditLog.WriteError(ex.Message + " : " + ex.StackTrace);
                    return(new Tuple <bool, string>(false, GlobalVariable.ErrorMessage));
                }
                finally
                {
                    sqlConnection.Close();
                    sqlCommand.Dispose();
                    ds.Dispose();
                }
            }
        }