//EMAIL CLIENT CONTACT private void notifyClientContact(CarrierInvoiceProfile CarrierInvoice, ClaimService service, Claim myClaim, AdjusterMaster adjuster) { StringBuilder emailBody = new StringBuilder(); string password = null; string[] recipients = null; string smtpHost = null; int smtpPort = 0; string siteUrl = ConfigurationManager.AppSettings["siteUrl"].ToString(); string insuredName = Session["InsuredName"].ToString(); string subject = "Claim # " + myClaim.InsurerClaimNumber + ", Please Read Claim Note, Claim Ruler Note for : " + insuredName; CRM.Data.Entities.SecUser user = null; string itsgHost = ConfigurationManager.AppSettings["smtpHost"].ToString(); string itsgHostPort = ConfigurationManager.AppSettings["smtpPort"].ToString(); string itsgEmail = ConfigurationManager.AppSettings["smtpEmail"].ToString(); string itsgEmailPassword = ConfigurationManager.AppSettings["smtpPassword"].ToString(); string EmailService = ddlInvoiceServiceType.SelectedItem.Text; string EmailActivity = ddlActivity.SelectedItem.Text; string EmailDescription = txtServiceDescription.Text; string EmailInternal = txtMyComments.Text; string EmailQuantity = txtServiceQty.Text; string EmailDate = txtServiceDate.Text; string userName = SessionHelper.getUserName(); int.TryParse(itsgHostPort, out smtpPort); // get logged in user int userID = SessionHelper.getUserId(); //Convert.ToInt32(itsgHostPort); // get current user email info user = SecUserManager.GetByUserId(userID); // load email credentials smtpHost = user.emailHost; int.TryParse(user.emailHostPort, out smtpPort); // recipients recipients = new string[] { CarrierInvoice.AccountingContactEmail }; // build email body // .containerBox emailBody.Append("<div style=\"margin:auto;width:600px;border: 1px solid #DDDDE4; margin: auto;font-family: Tahoma, Arial,sans-serif;font-size: 12px;color: #808080;\">"); // .header //emailBody.Append("<div style=\"background-image:url(https://appv3.claimruler.com/images/email_header_small.jpg);background-repeat: no-repeat;background-size: 100% 100%;height:70px;\"></div>"); //emailBody.Append("<div><img src=\"http://app.claimruler.com/images/email_header_small.jpg\"></image></div>"); // .paneContentInner emailBody.Append("<div style=\"margin: 20px;\">"); emailBody.Append("Hi " + CarrierInvoice.AccountingContact + ",<br><br>"); emailBody.Append("The following activity was just logged on Claim # " + myClaim.InsurerClaimNumber + " for Insured: " + insuredName + "<br><br><br>"); emailBody.Append("<table >"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>Service:</b></td><td align=\"left\"> " + EmailService + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr>"); emailBody.Append("<td align=\"left\"><b>Activity:</b></td><td align=\"left\"> " + EmailActivity + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>Description:</b></td><td align=\"left\"> " + EmailDescription + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>Internal Comments:</b></td><td align=\"left\"> " + EmailInternal + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr></tr>"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>Adjuster:</b></td><td align=\"left\"> " + adjuster.adjusterName + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>User Name:</b></td><td align=\"left\"> " + userName + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>Service Date:</b></td><td align=\"left\"> " + EmailDate + "</td>"); emailBody.Append("</tr>"); emailBody.Append("<tr> "); emailBody.Append("<td align=\"left\"><b>Timer Quantity:</b></td><td align=\"left\"> " + EmailQuantity + "</td>"); emailBody.Append("</tr>"); emailBody.Append("</table ><br><br>"); emailBody.Append("</div>"); // inner containerBox emailBody.Append("</div>"); // paneContentInner emailBody.Append("</div>"); // containerBox //Core.EmailHelper.sendEmail(user.Email, recipients, null, "Claim Assignment Notification", emailBody.ToString(), null, user.emailHost, smtpPort, smtpEmail, smtpPassword, true); password = Core.SecurityManager.Decrypt(user.emailPassword); //Core.EmailHelper.sendEmail(user.Email, recipients, null, subject, emailBody.ToString(), null, user.emailHost, smtpPort, user.Email, password, user.isSSL ?? true); Core.EmailHelper.sendEmail(itsgEmail, recipients, null, subject, emailBody.ToString(), null, itsgHost, Convert.ToInt32(itsgHostPort), itsgEmail, itsgEmailPassword); }
protected void Page_Load(object sender, EventArgs e) { // access master page from nested master page Protected.ClaimRuler masterPage = Master.Master as Protected.ClaimRuler; // check user permission //masterPage.checkPermission(); clientID = SessionHelper.getClientId(); // get current lead leadID = SessionHelper.getLeadId(); // get current lead id claimID = SessionHelper.getClaimID(); // get current user userID = SessionHelper.getUserId(); // set directory where client can upload pictures for signature txtSignature.UploadedFilesDirectory = appPath + "/clientLogo/" + clientID; if (!Page.IsPostBack) { bindData(); userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string email = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; try { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(email, password); service.Url = new Uri(url); ContactsFolder contactsfolder = ContactsFolder.Bind(service, WellKnownFolderName.Contacts); int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50; ItemView view = new ItemView(int.MaxValue); view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName); FindItemsResults <Item> contactItems = service.FindItems(WellKnownFolderName.Contacts, view); DataTable table = new DataTable(); table.Columns.Add("FirstName", typeof(string)); table.Columns.Add("LastName", typeof(string)); table.Columns.Add("CompanyName", typeof(string)); table.Columns.Add("Email", typeof(string)); table.Columns.Add("ContactType", typeof(string)); foreach (GridRecord crow in contractGrid.Rows) { DataRow row = table.NewRow(); row[0] = crow.Items[0].Text; row[1] = crow.Items[1].Text; //row[2] = crow.Cells[2].Text; row[3] = crow.Items[3].Text; row[4] = crow.Items[4].Text; table.Rows.Add(row); } foreach (Item item in contactItems) { if (item is Microsoft.Exchange.WebServices.Data.Contact) { item.Load(); Microsoft.Exchange.WebServices.Data.Contact contact = item as Microsoft.Exchange.WebServices.Data.Contact; DataRow row = table.NewRow(); row[0] = contact.GivenName; row[1] = contact.Surname; row[3] = contact.EmailAddresses[0].Address; row[4] = "Outlook"; table.Rows.Add(row); } } contractGrid.DataSourceID = null; contractGrid.Columns.Clear(); contractGrid.DataBind(); contractGrid.DataSource = table; contractGrid.DataBind(); } catch (Exception ex) { } } }
protected void bindData() { //AppraiserMaster appraiser = null; Claim claim = null; //List<LeadContact> contacts = null; List <DocumentList> attachments = null; //ContractorMaster contractor = null; //List<SecUser> users = null; Leads lead = null; //Data.UmpireMaster umpire = null; // get email for user sending email CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(userID); if (user != null) { txtEmailFrom.Text = user.Email; txtEmailCC.Text = user.Email; txtSignature.Text = user.emailSignature ?? ""; } claim = ClaimsManager.Get(this.claimID); if (claim != null) { attachments = new List <DocumentList>(); lead = claim.LeadPolicy.Leads; // build subject line txtEmailSubject.Text = string.Format("{0} Claim #: {1}", lead.policyHolderName, claim.AdjusterClaimNumber); // load legacy documents List <LeadsDocument> documents = LeadsUploadManager.getLeadsDocumentByLeadID((int)claim.LeadPolicy.LeadId); if (documents != null && documents.Count > 0) { foreach (LeadsDocument x in documents) { DocumentList attachment = new DocumentList(); attachment.DocumentName = x.Description; attachment.DocumentPath = string.Format("LeadsDocument/{0}/{1}/{2}", x.LeadId, x.LeadDocumentId, // document id x.DocumentName); // document file name attachments.Add(attachment); } } // load claim documents List <ClaimDocument> claimDocuments = ClaimDocumentManager.GetAll(this.claimID); if (claimDocuments != null && claimDocuments.Count > 0) { foreach (ClaimDocument x in claimDocuments) { DocumentList attachment = new DocumentList(); attachment.DocumentName = x.Description; attachment.DocumentPath = string.Format("ClaimDocuments/{0}/{1}/{2}", x.ClaimID, x.ClaimDocumentID, // document id x.DocumentName); // document file name attachments.Add(attachment); } } lbxDocuments.DataSource = attachments; lbxDocuments.DataBind(); //// load legacy contacts //contacts = LeadContactManager.GetContactByLeadID(leadID); //// add adjusters to contact list //if (claim.AdjusterMaster != null) // addToContactList(claim.AdjusterMaster.AdjusterName, claim.AdjusterMaster.email, contacts); //// add appraiser to contact list //if (lead.AppraiserID != null) { // appraiser = AppraiserManager.Get((int)lead.AppraiserID); // contacts.Add(new LeadContact { // Email = appraiser.Email, // ContactName = appraiser.AppraiserName // }); //} //// add contractor to contact list //if (lead.ContractorID != null) { // contractor = ContractorManager.Get((int)lead.ContractorID); // contacts.Add(new LeadContact { // Email = lead.ContractorMaster.Email, // ContactName = lead.ContractorMaster.ContractorName // }); //} //// add umpire to contact list //if (lead.UmpireID != null) { // umpire = UmpireManager.Get((int)lead.UmpireID); // contacts.Add(new LeadContact { // Email = lead.UmpireMaster.Email, // ContactName = lead.UmpireMaster.UmpireName // }); //} // add users 2013-12-12 //users = SecUserManager.GetUsers(clientID); //if (users != null && users.Count > 0) { // users.ForEach(x => // contacts.Add(new LeadContact { // Email = x.Email, // ContactName = x.FirstName ?? "" + " " + x.LastName ?? "" // })); //} } //lbxContacts.DataSource = contacts; //lbxContacts.DataBind(); }
private void notifyAdjuster(AdjusterMaster adjuster, StringBuilder claimList) { StringBuilder emailBody = new StringBuilder(); string password = null; string[] recipients = null; string smtpHost = null; int smtpPort = 0; string siteUrl = ConfigurationManager.AppSettings["siteUrl"].ToString(); string subject = "Claim Assignment Notification"; CRM.Data.Entities.SecUser user = null; string itsgHost = ConfigurationManager.AppSettings["smtpHost"].ToString(); string itsgHostPort = ConfigurationManager.AppSettings["smtpPort"].ToString(); string itsgEmail = ConfigurationManager.AppSettings["smtpEmail"].ToString(); string itsgEmailPassword = ConfigurationManager.AppSettings["smtpPassword"].ToString(); int.TryParse(itsgHostPort, out smtpPort); // get logged in user int userID = SessionHelper.getUserId(); //Convert.ToInt32(itsgHostPort); // get current user email info user = SecUserManager.GetByUserId(userID); // load email credentials smtpHost = user.emailHost; int.TryParse(user.emailHostPort, out smtpPort); // recipients recipients = new string[] { adjuster.email }; // build email body // .containerBox emailBody.Append("<div style=\"margin:auto;width:600px;border: 1px solid #DDDDE4; margin: auto;font-family: Tahoma, Arial,sans-serif;font-size: 12px;color: #808080;\">"); // .header //emailBody.Append("<div style=\"background-image:url(https://appv3.claimruler.com/images/email_header_small.jpg);background-repeat: no-repeat;background-size: 100% 100%;height:70px;\"></div>"); emailBody.Append("<div><img src=\"http://app.claimruler.com/images/email_header_small.jpg\"></image></div>"); // .paneContentInner emailBody.Append("<div style=\"margin: 20px;\">"); emailBody.Append("Hi " + adjuster.adjusterName + "!<br><br>"); emailBody.Append("Your firm uses Claim Ruler software for claims management and the following claim(s) have been assigned to you.<br><br>"); emailBody.Append("Please review claim(s) right away to begin handling the file(s). Time is of the essence!<br><br>"); emailBody.Append("<table style=\"width:550px;\">"); emailBody.Append(string.Format("<tr align=\"center\"><th scope=\"col\">{0}</th><th scope=\"col\">{1}</th><th scope=\"col\">{2}</th></tr>", "Insured Name", "Adjuster Claim #", "Insurer Claim #")); // claim list emailBody.Append(claimList.ToString()); // end email body emailBody.Append("</table>"); emailBody.Append(string.Format("<p><a href=\"{0}/login.aspx\">Please click here to access Claim Ruler.</a></p>", siteUrl)); emailBody.Append("<br>Thank you."); emailBody.Append("</div>"); // inner containerBox emailBody.Append("</div>"); // paneContentInner emailBody.Append("</div>"); // containerBox //Core.EmailHelper.sendEmail(user.Email, recipients, null, "Claim Assignment Notification", emailBody.ToString(), null, user.emailHost, smtpPort, smtpEmail, smtpPassword, true); password = Core.SecurityManager.Decrypt(user.emailPassword); //Core.EmailHelper.sendEmail(user.Email, recipients, null, subject, emailBody.ToString(), null, user.emailHost, smtpPort, user.Email, password, user.isSSL ?? true); Core.EmailHelper.sendEmail(user.Email, recipients, null, subject, emailBody.ToString(), null, itsgHost, Convert.ToInt32(itsgHostPort), itsgEmail, itsgEmailPassword); }
protected void btnSend_Click(object sender, EventArgs e) { string[] attachments = null; ClaimComment comment = null; string emailTo = txtEmailTo.Text.Trim().Replace(",", ";"); string emailBody = null; string[] cc = null; string cc_list = null; string decryptedPassword = null; ArrayList documentArray = null; bool isSSL = true; int leadID = 0; int port = 0; string[] recipients = emailTo.Split(';'); string subject = null; CRM.Data.Entities.SecUser user = null; Page.Validate("email"); if (!Page.IsValid) { return; } // get user information user = SecUserManager.GetByUserId(SessionHelper.getUserId()); if (user == null) { clearFields(); return; } // decrypt user password decryptedPassword = Core.SecurityManager.Decrypt(user.emailPassword); // email CC if (!string.IsNullOrEmpty(txtEmailCC.Text)) { cc_list = txtEmailCC.Text.Replace(",", ";"); cc = cc_list.Split(';'); } // get attachments if (lbxDocuments != null && lbxDocuments.Items != null && lbxDocuments.Items.Count > 0) { documentArray = new ArrayList(); foreach (ListItem item in lbxDocuments.Items) { if (item.Selected) { string documentPath = appPath + "/" + item.Value; documentArray.Add(documentPath); } } attachments = documentArray.ToArray(typeof(string)) as string[]; } // add to comments int.TryParse(user.emailHostPort, out port); emailBody = string.Format("<div>{0}</div><div>{1}</div>", txtEmailText.Text.Trim(), txtSignature.Text.Trim()); subject = txtEmailSubject.Text.Trim(); //isSSL = user.isSSL ?? true; //string smtpHost = ConfigurationManager.AppSettings["smtpHost"].ToString(); //int smtpPort = ConfigurationManager.AppSettings["smtpPort"] == null ? 25 : Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]); //string smtpEmail = ConfigurationManager.AppSettings["smtpEmail"].ToString(); //string smtpPassword = ConfigurationManager.AppSettings["smtpPassword"].ToString(); try { // Core.EmailHelper.sendEmail(txtEmailFrom.Text, recipients, cc, subject, emailBody, attachments, smtpHost, smtpPort, smtpEmail, smtpPassword, isSSL); userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string emailaddress = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(emailaddress, password); service.Url = new Uri(url); EmailMessage email = new EmailMessage(service); foreach (var recipient in recipients) { if (!string.IsNullOrEmpty(recipient)) { email.ToRecipients.Add(recipient); } } email.Subject = subject; email.Body = new MessageBody(emailBody); foreach (var filename in attachments) { if (!string.IsNullOrEmpty(filename)) { email.Attachments.AddFileAttachment(filename); } } email.SendAndSaveCopy(); comment = new ClaimComment(); comment.ClaimID = this.claimID; comment.CommentDate = DateTime.Now; comment.CommentText = string.Format("Sent Email:<br/>To: {0}<br/>Subject: {1}<br/>{2}", txtEmailTo.Text.Trim(), txtEmailSubject.Text.Trim(), txtEmailText.Text.Trim()); comment.IsActive = true; comment.UserId = this.userID; ClaimCommentManager.Save(comment); clearFields(); lblMessage.Text = "Email sent successfully."; lblMessage.CssClass = "ok"; } catch (Exception ex) { lblMessage.Text = "Incorrect Email Settings. Email not sent."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } }
protected void btnCreateCarrierAccount_Click(object sender, EventArgs e) { int clientID = 0; int contactID = 0; Contact contact = null; string newUserName = null; string password = null; CRM.Data.Entities.SecUser newUserAccount = null; CRM.Data.Entities.SecUser user = null; lblMessage.Text = string.Empty; lblMessage.CssClass = string.Empty; Page.Validate("Account"); if (!Page.IsValid) { return; } clientID = SessionHelper.getClientId(); newUserName = txtUserName.Text.Trim(); // check username is not taken if (SecUserManager.IsUserNameExist(newUserName)) { lblMessage.Text = "User Name " + newUserName + " is already taken."; lblMessage.CssClass = "error"; return; } // initialize user object user = new CRM.Data.Entities.SecUser(); user.UserName = newUserName; user.FirstName = txtFirstName.Text; user.LastName = txtLastName.Text; user.Status = true; user.isSSL = true; // assign client for this user user.ClientID = clientID; // attach carrier to user user.CarrierID = this.carrierID; user.CreatedBy = Core.SessionHelper.getUserId(); user.CreatedOn = DateTime.Now; user.Email = txtContactEmail.Text.Trim(); // assign selected role user.RoleId = Convert.ToInt32(ddlClientRoles.SelectedValue); // random password password = Guid.NewGuid().ToString().Substring(0, 8); // encrypt password user.Password = Core.SecurityManager.Encrypt(password); try { using (TransactionScope scope = new TransactionScope()) { // add new user account newUserAccount = SecUserManager.Save(user); // associate new user account with contact contactID = Convert.ToInt32(ViewState["ContactID"]); contact = ContactManager.Get(contactID); contact.UserID = newUserAccount.UserId; ContactManager.Save(contact); scope.Complete(); } // email adjuster about newly created account Core.EmailHelper.emailUserCredentials(newUserAccount); lblMessage.Text = string.Format("User Account '{0}' was created and credentials were emailed to the user.", newUserName); lblMessage.CssClass = "ok"; // hide create account button this.btnShowCreateAccount.Visible = false; this.btnCreateCarrierAccount.Visible = false; } catch (Exception ex) { lblMessage.Text = "Unable to create user account."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } }
protected void btnSend_Click(object sender, EventArgs e) { string[] attachments = null; int clientID = 0; string[] recipient = null; List <string> emails = null; CRM.Data.Entities.SecUser user = null; string decryptedPassword = null; string fromEmail = null; string subject = txtEmailSubject.Text.Trim(); string bodyText = txtEmailText.Text.Trim(); user = SecUserManager.GetByUserId(SessionHelper.getUserId()); if (user == null) { return; } int roleID = SessionHelper.getUserRoleId(); if (roleID == (int)UserRole.Client || roleID == (int)UserRole.SiteAdministrator) { clientID = SessionHelper.getClientId(); emails = LeadsManager.GetLeadEmails(clientID); } else { emails = LeadsManager.GetLeadEmails(); } fromEmail = user.Email; txtEmailText.Text += "\n\n" + user.emailSignature ?? ""; decryptedPassword = Core.SecurityManager.Decrypt(user.emailPassword); if (fileUpload.HasFile && fileUpload.PostedFile.ContentLength > 0) { attachments = new string[] { Path.GetFullPath(fileUpload.PostedFile.FileName) }; } if (emails != null && emails.Count > 0) { try { foreach (string email in emails) { recipient = new string[] { email }; Core.EmailHelper.sendEmail(fromEmail, recipient, null, subject, bodyText, attachments, user.Email, decryptedPassword); } lblMessage.Text = "Email broadcast complete."; lblMessage.CssClass = "ok"; } catch (Exception ex) { lblMessage.Text = "Email broadcast failed."; lblMessage.CssClass = "error"; } } }
protected void btnSave_Click(object sender, EventArgs e) { lblError.Text = string.Empty; lblSave.Text = string.Empty; lblMessage.Text = string.Empty; lblError.Visible = false; lblSave.Visible = false; lblMessage.Visible = false; bool isnew = false; bool isError = false; CRM.Data.Entities.SecUser user = null; Page.Validate("register"); if (!Page.IsValid) { return; } // 2013-08-06 tortega int clientID = Core.SessionHelper.getClientId(); int roleID = Core.SessionHelper.getUserRoleId(); try { using (TransactionScope scope = new TransactionScope()) { if (hfUserId.Value == "0") { isnew = true; user = new CRM.Data.Entities.SecUser(); user.ClientID = clientID; } else { user = SecUserManager.GetByUserId(Convert.ToInt32(hfUserId.Value)); } // ** Add User ** // if (isnew) { bool userExist = SecUserManager.IsUserNameExist(txtUserName.Text.Trim()); //bool emailExist = SecUserManager.IsEmailExist(txtEmail.Text.Trim()); // 2013-08-06 tortega if (clientID > 0 && ClientManager.UsersLimitReached(clientID)) { throw new Exception("Maximum number of users reached."); } if (userExist) { throw new Exception("User Name already exists."); } } user.FirstName = txtFirstName.Text.Trim(); user.LastName = txtLastName.Text.Trim(); user.Email = txtEmail.Text; user.UserName = txtUserName.Text.Trim(); //user.Password = SecurityManager.Encrypt(txtPassWord.Text); user.RoleId = Convert.ToInt32(ddlRole.SelectedValue); user.Status = ddlStatus.SelectedValue == "1" ? true : false; user.Blocked = false; user.isViewAllClaims = cbxViewAllClaims.Checked; if (chkPassword.Checked == true || isnew) { user.Password = SecurityManager.Encrypt(txtPassWord.Text); } user.UserName = txtUserName.Text.Trim(); user.FirstName = txtFirstName.Text.Trim(); user.LastName = txtLastName.Text.Trim(); user.Email = txtEmail.Text; user.Status = ddlStatus.SelectedValue == "1" ? true : false; user.Blocked = user.Blocked; user.RoleId = Convert.ToInt32(ddlRole.SelectedValue); user = SecUserManager.Save(user); //clearControls(); scope.Complete(); if (isnew) { lblSave.Text = "User account has been created. User credentials sent via email."; } else { lblSave.Text = "User account saved."; } lblSave.Visible = true; btnResetPassword.Visible = true; } } catch (Exception ex) { isError = true; lblError.Text = ex.Message; lblError.Visible = true; Core.EmailHelper.emailError(ex); } finally { if (isnew && isError == false) { // email user account info Core.EmailHelper.emailUserCredentials(user); } } }
private void FillForm() { string photoPath = null; int userId = Session["UID"] != null?Convert.ToInt32(Session["UID"]) : 0; int roleID = SessionHelper.getUserRoleId(); if (userId > 0) { hfUserId.Value = userId.ToString(); lblheading.Text = "Edit User Details"; chkPassword.Enabled = true; btnResetPassword.Visible = true; } else { lblheading.Text = "New User"; chkPassword.Visible = false; btnResetPassword.Visible = false; } bindRole(); if (userId > 0) { // update user CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(Convert.ToInt32(userId)); if (user.UserId > 0 && user.UserName != null) { txtFirstName.Text = user.FirstName; txtLastName.Text = user.LastName; txtEmail.Text = user.Email; txtUserName.Text = user.UserName; txtPassWord.Text = SecurityManager.Decrypt(user.Password); ViewState["Password"] = txtPassWord.Text; txtPassWord.Attributes.Add("value", "12345"); txtPassWord.Enabled = false; txtRePassWord.Text = SecurityManager.Decrypt(user.Password); txtRePassWord.Attributes.Add("value", "12345"); txtRePassWord.Enabled = false; cbxViewAllClaims.Checked = user.isViewAllClaims ?? false; // disable role DDL when client is editing his own client id if (roleID == (int)UserRole.Client && user.RoleId == (int)UserRole.Client) { ddlRole.Enabled = false; ddlRole.Items.Add(new ListItem("Client", user.RoleId.ToString())); } else { ddlRole.Enabled = true; } ddlRole.SelectedValue = user.RoleId.ToString(); if (user.Status.ToString() == "True") { ddlStatus.SelectedValue = "1"; } else { ddlStatus.SelectedValue = "0"; } if (user.ClientID != null) { ddlClient.SelectedValue = user.ClientID.ToString(); } userPhoto.ImageUrl = Core.Common.getUserPhotoURL(user.UserId); //txtEmailSignature.Text = user.emailSignature; } if (user.RoleId == 1) { CRM.Data.Entities.SecUser loginUser = SecUserManager.GetByUserId(Convert.ToInt32(Session["UserId"])); ddlStatus.Enabled = false; txtUserName.Enabled = false; } } }
protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e) { lblError.Text = string.Empty; lblSave.Text = string.Empty; lblMessage.Text = string.Empty; lblMessage.Visible = false; lblError.Visible = false; lblSave.Visible = false; if (e.CommandName.Equals("DoEdit")) { Session["UID"] = e.CommandArgument; var url = "~/protected/admin/UserEdit.aspx"; Response.Redirect(url); } else if (e.CommandName.Equals("DoDelete")) { try { var user = SecUserManager.GetByUserId(Convert.ToInt32(e.CommandArgument)); user.Status = false; SecUserManager.Save(user); DoBind(); lblSave.Text = "Record Deleted Sucessfully."; lblSave.Visible = true; } catch (Exception ex) { lblError.Text = "Record Not Deleted."; lblError.Visible = true; } } else if (e.CommandName.Equals("DoView")) { Session["UIDV"] = e.CommandArgument; var url = "~/protected/admin/UserDetail.aspx"; Response.Redirect(url); Response.Redirect(url); } else if (e.CommandName.Equals("DoUnlock")) { try { var user = SecUserManager.GetByUserId(Convert.ToInt32(e.CommandArgument)); user.Blocked = false; SecUserManager.Save(user); DoBind(); lblSave.Text = "User Unlock Successfully."; lblSave.Visible = true; } catch (Exception ex) { lblError.Text = "User Not Unlocked."; lblError.Visible = true; } } else if (e.CommandName.Equals("Dolock")) { try { var user = SecUserManager.GetByUserId(Convert.ToInt32(e.CommandArgument)); user.Blocked = true; SecUserManager.Save(user); DoBind(); lblSave.Text = "User lock Successfully."; lblSave.Visible = true; } catch (Exception ex) { lblError.Text = "User Not locked."; lblError.Visible = true; } } else if (e.CommandName.Equals("DoImpersonate")) { impersonateUser(Convert.ToInt32(e.CommandArgument)); } }
protected void btnDocumentsSearch_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtKeyword.Text)) { lblErrorMSg.Visible = true; } else { lblErrorMSg.Visible = false; int userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string email = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; try { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(email, password); service.Url = new Uri(url); ItemView view = new ItemView(int.MaxValue); Microsoft.Exchange.WebServices.Data.SearchFilter searchFilter = new Microsoft.Exchange.WebServices.Data.SearchFilter.ContainsSubstring(ItemSchema.Body, txtKeyword.Text); instanceResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view); DataTable table = GetTable(); foreach (var item in instanceResults.Items) { item.Load(); //Console.Clear(); EmailMessage msg = item as EmailMessage; DataRow row = table.NewRow(); string to = string.Empty; foreach (var rec in msg.ToRecipients) { to = to + rec.Address + ";"; } row["Subject"] = msg.Subject; string body = ExtractHtmlInnerText(msg.Body); if (body.Length > 2000) { body = body.Substring(0, 2000); } row["Body"] = "From :" + msg.From.Address + "\nTo :" + to + "\nSubject: " + msg.Subject + "\n" + body; row["No.of Attachments"] = msg.Attachments.Count.ToString(); row["Date"] = msg.DateTimeReceived.Date.ToShortDateString(); table.Rows.Add(row); } gvSearchResult.DataSource = table; gvSearchResult.DataBind(); pnlSearchResult.Visible = true; } catch (Exception ex) { lblErrorMSg.Text = "Incorrect Email Settings"; lblErrorMSg.Visible = true; } } }
protected void emailDocumentLink(string finalReportPath, string emailTo, int claimID) { int userID = Core.SessionHelper.getUserId(); Claim claim = null; string password = null; int port = 0; string[] recipients = null; string subject = null; Leads lead = null; string encryptedQuery = null; StringBuilder emailBody = null; string itsgHost = ConfigurationManager.AppSettings["smtpHost"].ToString(); string itsgHostPort = ConfigurationManager.AppSettings["smtpPort"].ToString(); string itsgEmail = ConfigurationManager.AppSettings["smtpEmail"].ToString(); string itsgEmailPassword = ConfigurationManager.AppSettings["smtpPassword"].ToString(); CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(userID); if (user != null && !string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.emailHost) && !string.IsNullOrEmpty(user.emailHostPort)) { claim = ClaimsManager.Get(claimID); if (claim != null) { lead = claim.LeadPolicy.Leads; if (string.IsNullOrEmpty(emailTo)) { recipients = new string[] { user.Email } } ; else { recipients = emailTo.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); } encryptedQuery = Core.SecurityManager.EncryptQueryString(claimID.ToString()); emailBody = new StringBuilder(); // .containerBox emailBody.Append("<div style=\"margin:auto;width:600px;border: 1px solid #DDDDE4; margin: auto;font-family: Tahoma, Arial,sans-serif;font-size: 12px;color: #808080;\">"); // header image emailBody.Append("<div style=\"padding:1px;\"><img src=\"http://app.claimruler.com/images/email_header_small.jpg\"></image></div>"); // .paneContentInner emailBody.Append("<div style=\"margin: 20px;\">"); subject = string.Format("{0} {1} wants to share {2} Adjuster Claim File with you", user.FirstName, user.LastName, lead.insuredName); emailBody.Append("<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-left:1px #b9e1fb solid;border-right:1px #b9e1fb solid;border-bottom:1px #b9e1fb solid;border-top:1px #b9e1fb solid;border-radius:0px 0px 4px 4px\" border=\"0\" align=\"center\">"); emailBody.Append("<tbody><tr><td colspan=\"3\" height=\"36\"></td></tr>"); emailBody.Append("<tr><td width=\"36\"></td>"); emailBody.Append("<td width=\"454\" style=\"font-size:14px;color:#444444;font-family:'Open Sans','Lucida Grande','Segoe UI',Arial,Verdana,'Lucida Sans Unicode',Tahoma,'Sans Serif';border-collapse:collapse\" align=\"left\" valign=\"top\">"); emailBody.Append(string.Format("{0} {1} invited you to a Claim Ruler Software shared file called \"{2}\"", user.FirstName, user.LastName, lead.insuredName)); string css = "border-radius:3px;border-left:1px #18639a solid;font-size:16px;border-bottom:1px #0f568b solid;padding:14px 7px 14px 7px;border-top:1px #2270ab solid;display:block;max-width:210px;font-family:'Open Sans','lucida grande','Segoe UI',arial,verdana,'lucida sans unicode',tahoma,sans-serif;text-align:center;background-image:-webkit-gradient(linear,0% 0%,0% 100%,from(rgb(55,163,235)),to(rgb(33,129,207)));width:210px;text-decoration:none;color:white;border-right:1px #18639a solid;font-weight:600;margin:0px auto 0px auto;background-color:#33a0e8"; // user app siteURL for report.pdf emailBody.Append(string.Format("<br/><br/><center><a style=\"{0}\" href=\"{1}/Temp/{2}\">View Report</a></center>", css, ConfigurationManager.AppSettings["siteURL"], Path.GetFileName(finalReportPath))); emailBody.Append(string.Format("<br/><br/><center><a style=\"{0}\" href=\"{1}/Content/Public.aspx?q={2}\">View Files</a></center></td>", css, ConfigurationManager.AppSettings["siteURL"], encryptedQuery)); emailBody.Append("<td width='36'></td></tr><tr><td colspan='3' height='36'></td></tr></tbody></table>"); emailBody.Append("</div>"); // paneContentInner emailBody.Append("</div>"); // containerBox //int.TryParse(user.emailHostPort, out port); int.TryParse(itsgHostPort, out port); password = SecurityManager.Decrypt(user.emailPassword); Core.EmailHelper.sendEmail(user.Email, recipients, null, subject, emailBody.ToString(), null, itsgHost, port, itsgEmail, itsgEmailPassword); } } else { throw new Exception("Unable to export claim. Please verify user email settings."); } }
protected void btnSave_Click(object sender, EventArgs e) { lblError.Text = string.Empty; lblSave.Text = string.Empty; lblSave.Visible = false; lblError.Visible = false; try { using (TransactionScope scope = new TransactionScope()) { SecRoleModuleManager.UpdateSecRoleModuleStatus(Convert.ToInt32(ddlRole.SelectedValue)); foreach (GridViewRow row in grdModule.Rows) { int check = 0; int checkParent = 0; GridView gv = (GridView)row.FindControl("gvSubModule"); HiddenField hfRoleModuleId = (HiddenField)row.FindControl("hfRoleModuleId"); HiddenField hfModuleId = (HiddenField)row.FindControl("hfModuleId"); if (hfRoleModuleId.Value == string.Empty) { hfRoleModuleId.Value = "0"; } CheckBox chkAllAdd = (CheckBox)row.FindControl("chkAllAdd"); CheckBox chkAllEdit = (CheckBox)row.FindControl("chkAllEdit"); CheckBox chkAllDel = (CheckBox)row.FindControl("chkAllDel"); CheckBox chkAllView = (CheckBox)row.FindControl("chkAllView"); SecRoleModule roleModuleMainGrid = SecRoleModuleManager.GetByRoleModuleId(Convert.ToInt32(hfRoleModuleId.Value)); if (chkAllView.Checked || chkAllAdd.Checked || chkAllEdit.Checked || chkAllEdit.Checked) { var secRoleModule = new CRM.Data.Entities.SecRoleModule { ModuleID = Convert.ToInt32(hfModuleId.Value), RoleID = Convert.ToInt32(ddlRole.SelectedValue), AddPermssion = chkAllAdd.Checked == true ? true : false, EditPermission = chkAllEdit.Checked == true ? true : false, DeletePermission = chkAllDel.Checked == true ? true : false, ViewPermission = chkAllView.Checked == true ? true : false, Status = 1, CreatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name), CreatedOn = DateTime.Now, UpdatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name), UpdatedOn = DateTime.Now, CreatedMachineIP = Request.ServerVariables["remote_addr"].ToString(), }; SecRoleModuleManager.SaveRoleModule(secRoleModule); checkParent = 1; } foreach (GridViewRow subGridRow in gv.Rows) { CheckBox chkAdd = (CheckBox)subGridRow.FindControl("chkAdd"); CheckBox chkEdit = (CheckBox)subGridRow.FindControl("chkEdit"); CheckBox chkDelete = (CheckBox)subGridRow.FindControl("chkDel"); CheckBox chkView = (CheckBox)subGridRow.FindControl("chkView"); HiddenField hfModuleIdChild = (HiddenField)subGridRow.FindControl("hfModuleIdChild"); SecRoleModule roleModule = SecRoleModuleManager.GetByRoleModuleId(Convert.ToInt32(hfRoleModuleId.Value)); if (chkAdd.Checked || chkEdit.Checked || chkDelete.Checked || chkView.Checked) { var secRoleModuleChild = new CRM.Data.Entities.SecRoleModule { ModuleID = Convert.ToInt32(hfModuleIdChild.Value), RoleID = Convert.ToInt32(ddlRole.SelectedValue), AddPermssion = chkAdd.Checked == true ? true : false, EditPermission = chkEdit.Checked == true ? true : false, DeletePermission = chkDelete.Checked == true ? true : false, ViewPermission = chkView.Checked == true ? true : false, Status = 1, CreatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name), CreatedOn = DateTime.Now, UpdatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name), UpdatedOn = DateTime.Now, CreatedMachineIP = Request.ServerVariables["remote_addr"].ToString(), }; SecRoleModuleManager.SaveRoleModule(secRoleModuleChild); check = 1; checkParent = 0; } GridView gvchild = (GridView)subGridRow.FindControl("gvSubModule1"); if (gvchild.Rows.Count > 0) { foreach (GridViewRow child in gvchild.Rows) { CheckBox chkAdd1 = (CheckBox)child.FindControl("chkAdd"); CheckBox chkEdit1 = (CheckBox)child.FindControl("chkEdit"); CheckBox chkDelete1 = (CheckBox)child.FindControl("chkDel"); CheckBox chkView1 = (CheckBox)child.FindControl("chkView"); HiddenField hfModuleIdChild1 = (HiddenField)child.FindControl("hfModuleIdChild1"); SecRoleModule roleModule1 = SecRoleModuleManager.GetByRoleModuleId(Convert.ToInt32(hfRoleModuleId.Value)); if (chkAdd1.Checked || chkEdit1.Checked || chkDelete1.Checked || chkView1.Checked) { var secRoleModuleChild = new CRM.Data.Entities.SecRoleModule { ModuleID = Convert.ToInt32(hfModuleIdChild1.Value), RoleID = Convert.ToInt32(ddlRole.SelectedValue), AddPermssion = chkAdd.Checked == true ? true : false, EditPermission = chkEdit.Checked == true ? true : false, DeletePermission = chkDelete.Checked == true ? true : false, ViewPermission = chkView.Checked == true ? true : false, Status = 1, CreatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name), CreatedOn = DateTime.Now, UpdatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name), UpdatedOn = DateTime.Now, CreatedMachineIP = Request.ServerVariables["remote_addr"].ToString(), }; SecRoleModuleManager.SaveRoleModule(secRoleModuleChild); check = 1; checkParent = 0; } } } } } CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(Convert.ToInt32(HttpContext.Current.User.Identity.Name)); if (user.SecRole.RoleId == Convert.ToInt32(ddlRole.SelectedValue)) { Session["rolePermission"] = refreshRolePermission = SecRoleModuleManager.getRolePermission(user.SecRole.RoleId).ToList(); } bindGrid(Convert.ToInt32(ddlRole.SelectedValue)); lblSave.Text = "Record Saved Sucessfully."; lblSave.Visible = true; scope.Complete(); } } catch (Exception ex) { lblError.Text = "Record Not Saved Sucessfully."; lblError.Visible = true; } }
private void bindTasks(DateTime fromDate, DateTime toDate) { List <LeadTask> tasks = null; Expression <Func <CRM.Data.Entities.Task, bool> > predicate = PredicateBuilder.True <CRM.Data.Entities.Task>(); if (roleID == (int)UserRole.Administrator) { } else if ((roleID == (int)UserRole.Client || roleID == (int)UserRole.SiteAdministrator) && clientID > 0) { // load all tasks for client (sort of admin) predicate = predicate.And(LeadTask => LeadTask.creator_id == clientID); predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate); // get overdue task for client predicate = predicate.Or(LeadTask => LeadTask.status_id == 1 && LeadTask.end_date <= toDate && LeadTask.creator_id == clientID); } else { // regular users predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate); predicate = predicate.And(LeadTask => LeadTask.owner_id == userID); } tasks = TasksManager.GetLeadTask(predicate, fromDate, toDate); if (rbOn.Checked) { userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string emailaddress = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(emailaddress, password); service.Url = new Uri(url); try { TasksFolder tasksfolder = TasksFolder.Bind(service, WellKnownFolderName.Tasks); ItemView view = new ItemView(int.MaxValue); FindItemsResults <Item> OutlookTasks = tasksfolder.FindItems(view); CalendarView calView = new CalendarView(fromDate, toDate); FindItemsResults <Item> instanceResults = service.FindItems(WellKnownFolderName.Calendar, calView); foreach (var item in instanceResults) { LeadTask newTask = new LeadTask(); Microsoft.Exchange.WebServices.Data.Appointment appointment = item as Microsoft.Exchange.WebServices.Data.Appointment; newTask.creator_id = userID; newTask.details = appointment.Subject; newTask.end_date = appointment.End; newTask.isAllDay = appointment.IsRecurring; newTask.text = appointment.Subject; newTask.priorityName = appointment.Importance.ToString(); newTask.owner_name = appointment.Organizer.Name; newTask.start_date = appointment.Start; tasks.Add(newTask); } foreach (var task in OutlookTasks) { task.Load(); Microsoft.Exchange.WebServices.Data.Task myTask = task as Microsoft.Exchange.WebServices.Data.Task; LeadTask newTask = new LeadTask(); newTask.creator_id = userID; newTask.details = ExtractHtmlInnerText(myTask.Body.Text); newTask.end_date = myTask.DueDate; newTask.isAllDay = myTask.IsRecurring; newTask.text = myTask.Subject; newTask.statusName = myTask.Status.ToString(); newTask.priorityName = myTask.Importance.ToString(); newTask.owner_name = myTask.Owner; if (myTask.StartDate == null) { newTask.start_date = myTask.DueDate; } else { newTask.start_date = myTask.StartDate; } tasks.Add(newTask); } } catch (Exception ex) { } } // show tasks gvTasks.DataSource = tasks; gvTasks.DataBind(); }
// bind users to scheduler private void bindResources() { List <UserStaff> staffMembers = null; Resource resource = null; CRM.Data.Entities.SecUser secUser = null; WebScheduleInfo1.VisibleResources.Clear(); switch (roleID) { case (int)UserRole.Client: case (int)UserRole.SiteAdministrator: staffMembers = SecUserManager.GetStaff(clientID); if (staffMembers != null && staffMembers.Count > 0) { ActiveResourceKey = staffMembers[0].UserId.ToString(); foreach (UserStaff user in staffMembers) { resource = new Resource(); resource.DataKey = user.UserId.ToString(); resource.Name = user.StaffName; resource.EmailAddress = user.EmailAddress; WebScheduleInfo1.VisibleResources.Add(resource); } } break; default: secUser = SecUserManager.GetByUserId(userID); if (secUser != null) { resource = new Resource(); resource.DataKey = secUser.UserId.ToString(); resource.Name = string.Format("{0} {1}", secUser.FirstName, secUser.LastName); resource.EmailAddress = secUser.Email; WebScheduleInfo1.VisibleResources.Add(resource); } break; } //WebScheduleInfo1.VisibleResources[0] == unassigned if (WebScheduleInfo1 != null && WebScheduleInfo1.VisibleResources != null && WebScheduleInfo1.VisibleResources.Count > 0) { if (!string.IsNullOrEmpty(ActiveResourceKey)) { Resource activeResource = WebScheduleInfo1.VisibleResources.GetResourceFromKey(ActiveResourceKey); if (activeResource != null && !string.IsNullOrEmpty(activeResource.Name)) { WebScheduleInfo1.ActiveResourceName = activeResource.Name; } } else { WebScheduleInfo1.ActiveResourceName = WebScheduleInfo1.VisibleResources[1].Name; ActiveResourceKey = WebScheduleInfo1.VisibleResources[1].DataKey.ToString(); } } }
protected void btnSave_Click(object sender, EventArgs e) { int clientID = 0; Client client = null; CRM.Data.Entities.SecUser user = null; bool isNew = false; int invoiceSettingID = 0; int userID = 0; Page.Validate("Client"); if (!Page.IsValid) { return; } if (int.TryParse(hfclientid.Value, out clientID) && clientID > 0) { // update existing client = ClientManager.Get(clientID); } else { // new user client = new Client(); // default value client.InactivityDays = 30; isNew = true; } if (client != null) { try { client.ClientTypeID = Convert.ToInt32(ddlClientType.SelectedValue); client.FirstName = txtFirstName.Text.Trim(); client.LastName = txtLastName.Text.Trim(); client.BusinessName = txtBusinessName.Text.Trim(); client.StreetAddress1 = txtAddress.Text.Trim(); client.CityId = Convert.ToInt32(ddlCity.SelectedValue); client.StateId = Convert.ToInt32(ddlState.SelectedValue); client.ZipCode = ddlZipCode.SelectedValue; client.PrimaryPhoneNo = txtPhone.Text.Trim(); client.SecondaryPhoneNo = txtFaxNumber.Text.Trim(); client.PrimaryEmailId = txtEmail.Text.Trim(); client.Active = 1; client.maxUsers = string.IsNullOrEmpty(txtNumberUsers.Text) ? 1 : Convert.ToInt32(txtNumberUsers.Text); client.FeePerContract = string.IsNullOrEmpty(txtFeePerContract.Text) ? 1 : Convert.ToDecimal(txtFeePerContract.Text); client.FederalIDNo = txtFederalTaxID.Text.Trim(); client.MaxLeads = Convert.ToInt32(string.IsNullOrEmpty(txtMaxLeads.Text) ? "0" : txtMaxLeads.Text); client.isTrial = cbxTrial.Checked; client.isShowTasks = cbxShowTasks.Checked; client.InactivityDays = string.IsNullOrEmpty(txtInactivityPeriod.Text) ? 0 : Convert.ToInt32(txtInactivityPeriod.Text); // imap settings client.imapHost = txtImapHost.Text.Trim(); client.imapHostPort = string.IsNullOrEmpty(txtImapHostPort.Text) ? 0 : Convert.ToInt32(txtImapHostPort.Text); client.imapHostUseSSL = cbxImapUseSSL.Checked; // invoice billing settings invoiceSettingID = Convert.ToInt32(ddlInvoiceSetting.SelectedValue); if (invoiceSettingID > 0) { client.InvoiceSettingID = invoiceSettingID; } client.InvoiceContingencyFee = txtContingencyFee.Value == null ? 0 : Convert.ToDecimal(txtContingencyFee.Value); // save client clientID = ClientManager.Save(client); if (isNew) { try { user = new CRM.Data.Entities.SecUser(); user.UserName = txtUserName.Text.Trim(); user.FirstName = txtFirstName.Text.Trim(); user.LastName = txtLastName.Text.Trim(); user.Status = true; user.RoleId = (int)UserRole.Client; user.Email = txtEmail.Text.Trim(); user.Password = SecurityManager.Encrypt(txtUserPassword.Text.Trim()); user.CreatedOn = DateTime.Now; user.CreatedBy = 1; user.UpdatedOn = DateTime.Now; user.UpdatedBy = 1; user.ClientID = clientID; CRM.Data.Entities.SecUser newUser = SecUserManager.Save(user); client = ClientManager.Get(clientID); if (client != null) { client.UserId = newUser.UserId; ClientManager.Save(client); } } catch (Exception ex) { lblMessage.Text = "Unable to create new user account."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } } else { // update user if (int.TryParse(hfuserid.Value, out userID) && userID > 0) { user = SecUserManager.GetByUserId(userID); if (user != null) { user.FirstName = txtFirstName.Text.Trim(); user.LastName = txtLastName.Text.Trim(); if (!string.IsNullOrEmpty(txtUserPassword.Text)) { user.Password = SecurityManager.Encrypt(txtUserPassword.Text.Trim()); } SecUserManager.Save(user); } } } lblMessage.Text = "Client changes saved."; lblMessage.CssClass = "ok"; } catch (Exception ex) { lblMessage.Text = "Unable to create new user account."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } } // if (client != null) { // clear after edit //Session.Remove("EditClientId"); //Response.Redirect("~/Protected/Admin/ClientList.aspx"); }