/// <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); } }
/// <summary> /// submits the order /// </summary> protected void SubmitOrder() { this.header.InnerText = "Your order has been submitted"; this.Master.SetLayout(this.header.InnerText, MasterPage.LayoutStyle.ContentOnly); // parse the controls on the page and generate an xml doc XmlDocument doc = this.xmlForm.GetResponse(pnlForm); XmlNode TractSearchNode = doc.SelectSingleNode("//field[@name = 'TractSearch']"); XmlNode BuyerNameNode = doc.SelectSingleNode("//field[@name = 'Buyer']"); if (TractSearchNode != null && TractSearchNode.InnerText.Equals("Yes") && BuyerNameNode != null && BuyerNameNode.InnerText.Equals("")) { BuyerNameNode.InnerText = "."; } Affinity.Request req = new Affinity.Request(this.phreezer); req.OrderId = order.Id; req.OriginatorId = this.GetAccount().Id; req.RequestTypeCode = this.rtype.Code; req.StatusCode = (this.isChange || this.rtype.Code == Affinity.RequestType.DefaultChangeCode) ? Affinity.RequestStatus.ChangedCode : Affinity.RequestStatus.DefaultCode; req.Xml = XmlForm.XmlToString(doc).Replace("’", "'"); req.Insert(); string surveyServices = req.GetDataValue("SurveyServices"); // if this is a change, we have to update any previous requests of the // same type so they are no longer recognized as the most current and we // know that they have been replaced by a newer request if (this.isChange) { Affinity.Request cr = new Affinity.Request(this.phreezer); cr.Load(this.changeId); // just a safety check to block any querystring monkeybusiness if (cr.OrderId == order.Id) { cr.IsCurrent = false; cr.Update(); } if (surveyServices != cr.GetDataValue("SurveyServices")) { // the survey services has been changed. it's either new or cancelled SendSurveyNotification(req, (surveyServices != "REQUIRED"), (surveyServices == "REQUIRED")); } } else if (surveyServices == "REQUIRED") { // send a notification that a new survey service has been requested SendSurveyNotification(req, false, true); } // if this was a property change, we need to update the master order record // as well so the data on the datagrids shows correctly if (this.rtype.Code == Affinity.RequestType.DefaultChangeCode) { order.ClientName = FindOrderField(pnlForm, "ClientName", order.ClientName); order.Pin = FindOrderField(pnlForm, "PIN", order.Pin); // case is different order.AdditionalPins = FindOrderField(pnlForm, "AdditionalPins", order.AdditionalPins); order.PropertyAddress = FindOrderField(pnlForm, "PropertyAddress", order.PropertyAddress2); order.PropertyAddress2 = FindOrderField(pnlForm, "PropertyAddress2", order.PropertyAddress); order.PropertyCity = FindOrderField(pnlForm, "PropertyCity", order.PropertyCity); order.PropertyState = FindOrderField(pnlForm, "PropertyState", order.PropertyState); order.PropertyZip = FindOrderField(pnlForm, "PropertyZip", order.PropertyZip); order.CustomerId = FindOrderField(pnlForm, "CustomerId", order.CustomerId); order.PropertyCounty = FindOrderField(pnlForm, "PropertyCounty", order.PropertyCounty); string closingDate = FindOrderField(pnlForm, "ClosingDate", order.ClosingDate.ToShortDateString()); try { order.ClosingDate = DateTime.Parse(closingDate); } catch (FormatException ex) { // TODO: check this at an earlier stage so we can roll back the transaction this.Master.ShowFeedback("Your order was updated however the new closing date was ignored because it was not a valid date in the format 'mm/dd/yyyy'", MasterPage.FeedbackType.Error); } } // we have to sync the status of the order because any new requests may change it // this will also call Update on the order if we've made any changes order.SyncStatus(); // notify affinity if specified in system settings SendNotification(req); //TODO: redirect to a thank-you page instead of just showing the message ShowConfirmation(); }