Ejemplo n.º 1
0
    /// <summary>
    /// Sends a notification to the affinity administrator if set in the system settings
    /// </summary>
    /// <param name="r"></param>
    protected void SendNotification(Affinity.Request r)
    {
        bool isNewRequest        = this.isChange == false && r.RequestTypeCode != Affinity.RequestType.DefaultChangeCode;
        bool isClosing           = (r.RequestTypeCode == Affinity.RequestType.ClosingRequestCode);
        bool isClerking          = (r.RequestTypeCode == Affinity.RequestType.ClerkingRequestCode);
        bool isNotSurveyServices = r.GetDataValue("SurveyServices").Equals("");

        string to = isClosing ? this.GetSystemSetting("ClosingRequestEmail") : this.GetSystemSetting("NewOrderEmail");

        if (isClerking)
        {
            if (to.Equals(""))
            {
                to = this.GetSystemSetting("ClerkingRequestEmail");
            }
            else
            {
                to += ", " + this.GetSystemSetting("ClerkingRequestEmail");
            }
        }

        string state = order.PropertyState.ToUpper();

        if (isNotSurveyServices && (state.Equals("IN") || state.Equals("MI") || state.Equals("FL")))
        {
            string addEmailTo = (state.Equals("IN"))? "*****@*****.**" : (state.Equals("MI"))? "*****@*****.**" : "*****@*****.**";
            if (to.Equals(""))
            {
                to = addEmailTo;
            }
            else
            {
                to += ", " + addEmailTo;
            }
        }

        // send the notification email if the originator wants it
        if (!to.Equals(""))
        {
            string url     = this.GetSystemSetting("RootUrl") + "AdminOrder.aspx?id=" + r.Order.Id.ToString();
            string subject = "Affinity " + r.RequestTypeCode + " Notification For " + r.Order.WorkingId;
            string header  = isNewRequest ? "New Request" : "Change Request";

            // send the email
            Com.VerySimple.Email.Mailer mailer = new Com.VerySimple.Email.Mailer(this.GetSystemSetting("SmtpHost"));

            string msg = "* This is an automated notification from the Affinity Web System *\r\n\r\n"
                         + "Type: " + r.RequestTypeCode + " - " + header + "\r\n"
                         + "Submitted By: " + r.Order.Account.FullName + "\r\n"
                         + "Working ID: " + r.Order.WorkingId + "\r\n"
                         + "PIN: " + r.Order.Pin + "\r\n"
                         + "Friendly: " + r.Order.ClientName + "\r\n"
                         + "Tracking Code: " + r.Order.CustomerId + "\r\n"
                         + "\r\n"
                         + "URL: " + url + "\r\n"
                         + "\r\n"
                         + "If you no longer wish to receive these notifications, please contact the Affinity Administrator.\r\n"
                         + this.GetSystemSetting("EmailFooter");

            mailer.Send(
                this.GetSystemSetting("SendFromEmail")
                , to.Replace(";", ",")
                , subject
                , msg);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Persist to DB and send email notification
    /// </summary>
    /// <returns>result of email notification</returns>
    protected string UpdateRequest()
    {
        if (!fuAttachment.HasFile)
        {
            return("No File Uploaded.");
        }

        this.request.StatusCode = "New";          // here we need the code, tho
        this.request.Note       = txtNote.Text;

        // if a file was provided, then upload it
        string ext      = System.IO.Path.GetExtension(fuAttachment.FileName);
        string fileName = "req_att_" + request.Id + "_" + DateTime.Now.ToString("yyyyMMddhhss") + "." + ext.Replace(".", "");

        Affinity.Attachment att = new Affinity.Attachment(this.phreezer);
        att.RequestId   = this.request.Id;
        att.Name        = txtAttachmentName.Text != "" ? txtAttachmentName.Text : ddFilePurpose.SelectedItem.Text;
        att.PurposeCode = ddFilePurpose.SelectedValue;
        att.Filepath    = fileName;
        att.MimeType    = ext;
        att.SizeKb      = 0;    // fuAttachment.FileBytes.GetUpperBound() * 1024;

        att.Insert();
        //TODO: block any harmful file types

        Affinity.UploadLog ul = new Affinity.UploadLog(this.phreezer);

        ul.AttachmentID    = att.Id;
        ul.AccountID       = this.request.Account.Id;
        ul.UploadAccountID = this.GetAccount().Id;
        ul.OrderID         = this.request.OrderId;
        ul.RequestID       = this.request.Id;

        ul.Insert();

        fuAttachment.SaveAs(Server.MapPath("./") + "attachments/" + fileName);

        Affinity.Account me = this.GetAccount();
        bool             isNotSurveyServices = this.request.GetDataValue("SurveyServices").Equals("");

        string to    = "[email protected], [email protected]";
        string state = this.request.Order.PropertyState.ToUpper();

        if (isNotSurveyServices && (state.Equals("IN") || state.Equals("MI") || state.Equals("FL")))
        {
            to += ", " + ((state.Equals("IN"))? "*****@*****.**" : (state.Equals("MI"))? "*****@*****.**" : "*****@*****.**");
        }

        MailMessage mm = new MailMessage(this.GetSystemSetting("SendFromEmail"), to, "File Uploaded for Affinity Order '" + this.request.Order.ClientName.Replace("\r", "").Replace("\n", "") + "' #" + this.request.Order.WorkingId, "File: " + att.Name + " (" + fileName + ") was uploaded to: #" + this.request.Order.WorkingId + " and was uploaded by: " + me.FirstName + " " + me.LastName + "<br /><br /><br />\r\n\r\n" + this.GetSystemSetting("EmailFooter"));

        mm.IsBodyHtml = true;
        mm.Priority   = MailPriority.Normal;

        if (File.Exists(Server.MapPath("./") + "attachments/" + fileName))
        {
            Attachment attch = new Attachment(Server.MapPath("./") + "attachments/" + fileName);
            attch.Name = fileName;

            mm.Attachments.Add(attch);
        }
        //SmtpClient sc = new SmtpClient(this.GetSystemSetting("SmtpHost"));
        //sc.Send(mm);

        Com.VerySimple.Email.Mailer mailer = new Com.VerySimple.Email.Mailer(this.GetSystemSetting("SmtpHost"));
        mailer.Send(mm);

        return("File was uploaded successfully.");
    }