Пример #1
0
        public void SendDailyEmail(HttpRequestMessage request, DAILYDC dailyDC, bool isNewDaily)
        {
            int       sentStatus   = 0;
            MESSAGEBL objMessageBL = new MESSAGEBL();

            try
            {
                MESSAGEDC objMessage = new MESSAGEDC();
                objMessage.FROM       = ConfigurationManager.AppSettings["AdminEmail"];
                objMessage.RECIPIENTS = new EMAIL_GROUPSBL().GetEmailsAgainstClient(dailyDC.CLIENT_PM);
                if (String.IsNullOrEmpty(objMessage.FROM))
                {
                    throw new Exception("Daily email cann't be sent.</br>Daily's Admin email address is not configured. Please contact your administrator.");
                }
                if (String.IsNullOrEmpty(objMessage.RECIPIENTS))
                {
                    throw new Exception("Daily email cann't be sent.</br>Daily's To email address is not configured. Please contact your administrator.");
                }

                if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["SMTPAddress"]))
                {
                    throw new Exception("Your password cannot be reset.</br>SMTP address is not configured.");
                }
                string subjectPrefix = isNewDaily ? "New" : "Update";
                dailyDC.HYLAN_PROJECT_ID = dailyDC.HYLAN_PROJECT_ID == null ? "Unknown" : dailyDC.HYLAN_PROJECT_ID;
                dailyDC.JOB_FILE_NUMBER  = dailyDC.JOB_FILE_NUMBER == null ? "Unknown" : dailyDC.JOB_FILE_NUMBER;
                objMessage.SUBJECT       = subjectPrefix + " Daily Submitted " + dailyDC.HYLAN_PROJECT_ID + "_" + dailyDC.JOB_FILE_NUMBER;


                string msgBody   = "<!DOCTYPE HTML><html><body><table cellspacing='0' cellpadding='0'>";
                string col1Style = " style='font-weight: bold;background-color: #f2f2f2;padding-left:10px;padding-right:10px;' ";
                string col2Style = " style='padding-left: 10px;' ";
                string rowStyle  = " style='height:25px;' ";
                msgBody += "<tr " + rowStyle + " ><td " + col1Style + " >Submitted by: </td><td " + col2Style + " > " + dailyDC.MODIFIED_BY_NAME + "<td></tr>";  //new to change need to display the name
                msgBody += "<tr " + rowStyle + " ><td " + col1Style + ">Date/Time: </td><td " + col2Style + " > " + dailyDC.MODIFIED_ON.ToString("MM/dd/yyyy HH:mm") + "<td></tr>";
                //msgBody += "<tr><td colspan = 2 >" + dailyDC.DAILY_TYPE_NAME + "<td></tr>";
                msgBody += "<tr " + rowStyle + " ><td " + col1Style + ">Daily Type: </td><td " + col2Style + " > " + dailyDC.DAILY_TYPE_NAME + "<td></tr>";
                msgBody += "<tr " + rowStyle + " ><td " + col1Style + ">Day: </td><td " + col2Style + " > " + dailyDC.DAILY_DAYS + "<td></tr>";
                msgBody += "<tr " + rowStyle + " ><td " + col1Style + ">Status: </td><td " + col2Style + " > " + dailyDC.DAILY_STATUS_NAME + "<td></tr>";
                msgBody += "<tr " + rowStyle + " ><td " + col1Style + ">Work Date: </td><td " + col2Style + " > " + dailyDC.DAILY_DATE.ToString("MM/dd/yyyy") + "<td></tr>";

                msgBody            += "</table></body></html>";
                objMessage.CONTENTS = msgBody;
                sentStatus          = objMessageBL.SendSMTPEmail(objMessage);
                if (sentStatus != 1)
                {
                    throw new Exception("Daily email cann't be sent.due to some error. Please contact your administrator.");
                }
            }
            catch (Exception exp)
            {
                int userID = Common.Utility.GetUserID(request);
                Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, userID);
            }
        }
Пример #2
0
        public int EmailResetPassword(string selectedUserIds, int currentUserId, string username, string emailId, bool isFromManageUsers)
        {
            int          updatedCount  = 0;
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();
            MESSAGEBL    objMessageBL  = new MESSAGEBL();
            string       NewPassword   = Utility.GenerateRandomPassword(8);

            try
            {
                string[] UserID    = selectedUserIds.Split(',');
                string[] UserName  = username.Split(',');
                string[] UserEmail = emailId.Split(',');
                objConnection.Open(true);
                updatedCount = objUSERDA.ResetPassword(objConnection, selectedUserIds, currentUserId, NewPassword);
                IsDirty      = objUSERDA.IsDirty;
                if (!IsDirty)
                {
                    MESSAGEDC objMessage = new MESSAGEDC();
                    objMessage.FROM = ConfigurationManager.AppSettings["AdminEmail"];
                    if (String.IsNullOrEmpty(objMessage.FROM))
                    {
                        throw new Exception("Your password cannot be reset.</br>Administrator's email address is not configured. Please contact your administrator.");
                    }
                    if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["SMTPAddress"]))
                    {
                        throw new Exception("Your password cannot be reset.</br>SMTP address is not configured.");
                    }
                    for (int i = 0; i < UserID.Length; i++)
                    {
                        objMessage.SUBJECT    = "Password Reset";
                        objMessage.RECIPIENTS = UserEmail[i];
                        string orginalContents = objMessage.CONTENTS;
                        string msgBody         = "<!DOCTYPE HTML><html><body><table>";
                        if (!isFromManageUsers)
                        {
                            msgBody += "<tr><td>Your password has been reset upon your request.</td></tr><tr><td></td></tr><tr><td></td></tr>";
                        }
                        else
                        {
                            msgBody += "<tr><td>Your password has been changed as below</td></tr><tr><td></td></tr><tr><td></td></tr>";
                        }
                        msgBody              += "<tr><td><b>Username:</b> " + UserName[i] + "</td></tr>";
                        msgBody              += "<tr><td><b>New Password:</b> " + NewPassword + "</td></tr>";
                        msgBody              += "</table></body></html>";
                        objMessage.CONTENTS   = msgBody;
                        objMessage.CREATED_BY = currentUserId;

                        updatedCount = objMessageBL.SendSMTPEmail(objMessage);

                        objMessage.CONTENTS = "Password has been reset for the user " + username;
                        //if (!isFromManageUsers)
                        //{
                        //    updatedCount = objMessageBL.UpdateDatabase(objMessage, objConnection, false);
                        //}
                    }
                }
                if (IsDirty)
                {
                    objConnection.Rollback();
                }
                else
                {
                    objConnection.Commit();
                }
            }
            catch (Exception ex)
            {
                objConnection.Rollback();
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(updatedCount);
        }
Пример #3
0
        public int Insert(List <USERDC> objUSERs)
        {
            int          insertedCount = 0;
            bool         IsDirty       = false;
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();

            try
            {
                objConnection.Open(true);
                foreach (USERDC objUSER in objUSERs)
                {
                    objUSER.CREATED_ON = objUSER.MODIFIED_ON = DateTime.Now;
                    objUSER.PASSWORD   = Utility.GenerateRandomPassword(8);
                    insertedCount      = objUSERDA.Insert(objConnection, objUSER);
                    if (objUSER.USER_ID == -111)
                    {
                        throw new Exception("User Name '" + objUSER.USER_NAME + "' already exists. All other changes saved successfully.");
                    }

                    //IsDirty = objUSERDA.IsDirty;
                    //if (IsDirty == false)
                    //{
                    //    objUSERDA.UpdateUserCompanies(objConnection, objUSER);
                    //}
                    //else
                    //{
                    //    break;
                    //}

                    int       EmailSent = 0;
                    MESSAGEDC objMsgDC  = new MESSAGEDC();
                    MESSAGEBL objMsgBL  = new MESSAGEBL();
                    USERDA    objUser   = new USERDA();
                    USERDC    objUserDC = new USERDC();

                    objUserDC = objUser.LoadByPrimaryKey(objConnection, objUSER.USER_ID);
                    Task.Run(() =>
                    {
                        StringBuilder strContents = new StringBuilder();
                        strContents.Append("<!DOCTYPE HTML><html><body><table>");
                        strContents.Append("<tr><td>Your profile for Hylan has been created.</td></tr><tr><td></td></tr>");
                        strContents.Append("<tr><td>Following are your account credentials:</td></tr><tr><td></td></tr>");
                        strContents.Append("<tr><td><b>Username:</b> " + objUSER.USER_NAME + "</td></tr>");
                        strContents.Append("<tr><td><b>Password:</b> " + objUSER.PASSWORD + "</td></tr>");
                        strContents.Append("</table></body></html>");
                        try
                        {
                            objMsgDC.FROM       = objUserDC.EMAIL_ADDRESS;
                            objMsgDC.SUBJECT    = "Your profile is created.";
                            objMsgDC.CONTENTS   = strContents.ToString();
                            objMsgDC.RECIPIENTS = objUSER.EMAIL_ADDRESS;
                            EmailSent           = objMsgBL.SendSMTPEmail(objMsgDC, true);
                        }
                        catch (Exception exp)
                        {
                            EPay.DataAccess.Utilities.InsertIntoErrorLog("Error: USER PROFILE CREATED NOTIFICATION EMAIL ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                        }
                    });
                }
                if (IsDirty)
                {
                    objConnection.Rollback();
                }
                else
                {
                    objConnection.Commit();
                }
            }
            catch (Exception ex)
            {
                objConnection.Rollback();
                throw ex;
            }
            finally
            {
                objConnection.Close();
            }
            return(insertedCount);
        }
Пример #4
0
        public int Update(List <USERDC> objUSERs, ref List <EXCEPTIONDC> lstExceptions)
        {
            int          updatedCount  = 0;
            DBConnection objConnection = new DBConnection();
            USERDA       objUSERDA     = new USERDA();

            try
            {
                foreach (USERDC objUSER in objUSERs)
                {
                    objConnection.Open(true);
                    try
                    {
                        objUSER.MODIFIED_ON = DateTime.Now;
                        updatedCount        = objUSERDA.Update(objConnection, objUSER);
                        if (objUSERDA.IsDirty)
                        {
                            break;
                        }

                        ///  Email sent an Match Complete
                        int           EmailSent     = 0;
                        MESSAGEDC     objMsgDC      = new MESSAGEDC();
                        MESSAGEBL     objMsgBL      = new MESSAGEBL();
                        List <string> lstUserEmails = new List <string>();
                        USERDA        objUser       = new USERDA();
                        USERDC        objUserDC     = new USERDC();

                        objUserDC = objUser.LoadByPrimaryKey(objConnection, objUSER.USER_ID);

                        // lstUserEmails = objUser.GetUsersEmailAddressByEventId(objUSER.USER_ID, "", 62, objConnection);

                        //if (lstUserEmails.Count > 0)
                        //{
                        Task.Run(() =>
                        {
                            //if (!lstUserEmails.Contains(objUSER.EMAIL_ADDRESS))
                            //    lstUserEmails.Add(objUSER.EMAIL_ADDRESS);
                            StringBuilder strContents = new StringBuilder();
                            strContents.Append("<!DOCTYPE HTML><html><body><table>");
                            strContents.Append("<tr><td>Profile for user  <b>" + objUSER.USER_NAME + "</b>. has been updated.");
                            strContents.Append("<tr><td>Please log into the system to verify changes.");
                            strContents.Append("</table></body></html>");
                            try
                            {
                                objMsgDC.FROM       = GetSMTPAdminEmail();
                                objMsgDC.SUBJECT    = "Your profile is changed.";
                                objMsgDC.CONTENTS   = strContents.ToString();
                                objMsgDC.RECIPIENTS = String.Join(";", objUserDC.EMAIL_ADDRESS);
                                EmailSent           = objMsgBL.SendSMTPEmail(objMsgDC, true);
                            }
                            catch (Exception exp)
                            {
                                EPay.DataAccess.Utilities.InsertIntoErrorLog("Error: USER PROFILE CHANGED NOTIFICATION EMAIL ", exp.Message + "\r\n" + exp.StackTrace, objUSER.MODIFIED_BY);
                            }
                        });
                        // }
                        objConnection.Commit();
                    }
                    catch (Exception exp)
                    {
                        EXCEPTIONDC objExcption = new EXCEPTIONDC();
                        objExcption.FIELD_ID          = objUSER.USER_ID;
                        objExcption.EXCEPTION_MESSAGE = exp.Message;
                        objExcption.STACK_TRACK       = exp.StackTrace;
                        lstExceptions.Add(objExcption);
                        objConnection.Rollback();
                        // throw exp;
                    }
                }
                if (lstExceptions.Count > 0)
                {
                    throw new Exception(lstExceptions[0].EXCEPTION_MESSAGE);
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                objConnection.Close();
            }

            return(updatedCount);
        }