Exemplo n.º 1
0
        /// <summary>
        /// A EmailQueue method to Read a specific EmailQueue type entry in the Database.
        /// </summary>
        /// <param name="id">Email ID assigned when creating the object</param>
        /// <returns>EmailQueue type object associated with the provided ID</returns>
        public EmailQueue ReadById(int id)
        {
            EmailQueue email = new EmailQueue();

            try
            {
                SqlCommand cmd = new SqlCommand("Email_ReadById", constr);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@EmailId", id);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                constr.Open();
                da.Fill(dt);
                constr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    email.EmailId     = Convert.ToInt32(dr["EmailId"]);
                    email.ToAddress   = Convert.ToString(dr["ToAddress"]);
                    email.FromAddress = Convert.ToString(dr["FromAddress"]);
                    email.Subject     = Convert.ToString(dr["Subject"]);
                    email.Body        = Convert.ToString(dr["Body"]);
                    email.Tries       = Convert.ToInt32(dr["Tries"]);
                    email.CreatedOn   = Convert.ToDateTime(dr["CreatedOn"]);
                    email.ModifiedOn  = Convert.ToDateTime(dr["ModifiedOn"]);
                    //book.DeletedOn = Convert.ToDateTime(dr["DeletedOn"]);
                    email.IsDeleted = Convert.ToBoolean(dr["IsDeleted"]);
                }
            }
            catch (Exception ex)
            {
                MethodBase method    = MethodBase.GetCurrentMethod();
                Exceptions exception = new Exceptions
                {
                    ExceptionNumber  = ex.HResult.ToString(),
                    ExceptionMessage = ex.Message,
                    ExceptionMethod  = method.Name,
                    ExceptionUrl     = HttpContext.Current.Request.Url.AbsoluteUri
                };
                int r = exceptionrepo.Exception_Create(exception);
                if (r == 0)
                {
                    exceptionrepo.Exception_InsertInLogFile(exception);
                }
                if (constr.State != ConnectionState.Open)
                {
                    constr.Close();
                    constr.Open();
                }
            }
            return(email);
        }
Exemplo n.º 2
0
 /// <summary>
 /// A EmailQueue method to Update a specific EmailQueue type entry in the Database.
 /// </summary>
 /// <param name="book">Email type object</param>
 /// <returns>True if the Updation was successful and False if it was not</returns>
 public bool Update(EmailQueue email)
 {
     try
     {
         SqlCommand cmd = new SqlCommand("Email_Update", constr);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@EmailId", email.EmailId);
         cmd.Parameters.AddWithValue("@ToAddress", email.ToAddress);
         cmd.Parameters.AddWithValue("@FromAddress", email.FromAddress);
         cmd.Parameters.AddWithValue("@Subject", email.Subject);
         cmd.Parameters.AddWithValue("@Body", email.Body);
         cmd.Parameters.AddWithValue("@Tries", email.Tries);
         constr.Open();
         int r = cmd.ExecuteNonQuery();
         constr.Close();
         if (r == 1)
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         MethodBase method    = MethodBase.GetCurrentMethod();
         Exceptions exception = new Exceptions
         {
             ExceptionNumber  = ex.HResult.ToString(),
             ExceptionMessage = ex.Message,
             ExceptionMethod  = method.Name,
             ExceptionUrl     = HttpContext.Current.Request.Url.AbsoluteUri
         };
         int r = exceptionrepo.Exception_Create(exception);
         if (r == 0)
         {
             exceptionrepo.Exception_InsertInLogFile(exception);
         }
         if (constr.State != ConnectionState.Open)
         {
             constr.Close();
             constr.Open();
         }
     }
     return(false);
 }