コード例 #1
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();
                }
            }
        }