private string SendInvitations(ApiUser hdUser, string recipients, string topic, string url) { Guid organizationId = hdUser.OrganizationId; int departmentId = hdUser.DepartmentId; int userId = hdUser.UserId; string Email = hdUser.LoginEmail; string userName = hdUser.FullName; string department = hdUser.DepartmentName; List <int> intUserIds = new List <int>(); string[] emails = recipients.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); recipients = ""; foreach (string email in emails) { if (!Utils.IsValidEmail(email)) { continue; } recipients += email + ";"; } if (string.IsNullOrWhiteSpace(recipients)) { throw new HttpError(HttpStatusCode.NotFound, "Incorrect Email(s)"); } string subject = topic; string from = "\"" + userName + " - " + department + "\"<" + Email + ">"; if (!string.IsNullOrWhiteSpace(recipients)) { try { string body = "Hi! You got " + topic + ".\n Please open this url to start chat: " + url + $". Or click <a href=\"{url}\" target=\"_blank\">{url}</a>"; MailNotification _mail_notification = new MailNotification(organizationId, departmentId, userId, from, recipients, subject, body); string _return_string = _mail_notification.Commit(true); } catch { throw new HttpError(HttpStatusCode.NotFound, "Email error."); } } else { throw new HttpError(HttpStatusCode.NotFound, "No recepients selected."); } return("OK"); }
internal static object SendInvoice(ApiUser hdUser, string invoice_id, string recipients, bool isPDFOnly = false) { Guid organizationId = hdUser.OrganizationId; int departmentId = hdUser.DepartmentId; int userId = hdUser.UserId; string Email = hdUser.LoginEmail; string userName = hdUser.FullName; string department = hdUser.DepartmentName; Models.Invoice invoice = GetInvoice(organizationId, departmentId, invoice_id, false); int AccountId = invoice.AccountId; List <int> intUserIds = new List <int>(); string[] emails = recipients.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); recipients = ""; invoice.recipients = AccountUsers.GetAccountUsers(organizationId, departmentId, invoice.AccountId); foreach (string email in emails) { if (!Utils.IsValidEmail(email)) { continue; } bool isAccountingContact = true; int userID = 0; string new_email = ""; AccountUser user = invoice.recipients.Find(r => r.Email.ToLower() == email.ToLower()); if (user != null) { isAccountingContact = user.AccountingContact; userID = user.Id; new_email = user.Email; } else { userId = bigWebApps.bigWebDesk.Data.Accounts.InsertUserIntoAccount(hdUser.OrganizationId, hdUser.DepartmentId, AccountId, email, 0, false); new_email = email; isAccountingContact = false; } if (!isAccountingContact) { bigWebApps.bigWebDesk.Data.Accounts.UpdateAccountContact(hdUser.OrganizationId, hdUser.DepartmentId, AccountId, userID, true); } recipients += new_email + ";"; } int ProjectId = invoice.ProjectId; int invoiceID = invoice.Id.Value; string subject = invoice.Customer + " | Invoice #" + invoiceID; string from = "\"" + userName + " - " + department + "\"<" + Email + ">"; if (!string.IsNullOrWhiteSpace(recipients)) { Instance_Config instanceConfig = new Models.Instance_Config(hdUser); string currency = string.IsNullOrWhiteSpace(instanceConfig.Currency) ? "$" : instanceConfig.Currency; try { string filename = "Invoice-" + invoiceID.ToString() + ".pdf"; string logoURL = string.Empty; string logoImageUrl = Files.GetOrganizationLargeLogoUrl(organizationId); if (!String.IsNullOrEmpty(logoImageUrl)) { logoURL = logoImageUrl; } logoImageUrl = Files.GetInstanceLargeLogoUrl(hdUser.InstanceId); if (!String.IsNullOrEmpty(logoImageUrl)) { logoURL = logoImageUrl; } byte[] pdfBytes = null; string body = ""; try { pdfBytes = bigWebApps.bigWebDesk.Data.Invoice.ExportPDF(organizationId, hdUser.InstanceId, departmentId, userId, invoiceID, "https://app.sherpadesk.com", currency, instanceConfig.Names.tech.a, instanceConfig.Names.ticket.a, instanceConfig.ProjectTracking, instanceConfig.Names.user.a, instanceConfig.QBUseQBInvoiceNumber, logoURL); if (isPDFOnly) { var sfile = new System.IO.MemoryStream(pdfBytes); return(new BWA.bigWebDesk.Api.Services.FilesService.FileResult(sfile, "application/pdf", filename)); } body = bigWebApps.bigWebDesk.Data.Invoice.ExportHtml(organizationId, hdUser.InstanceId, departmentId, userId, invoiceID, "https://app.sherpadesk.com", currency, instanceConfig.Names.tech.a, instanceConfig.Names.ticket.a, instanceConfig.ProjectTracking, instanceConfig.Names.user.a, instanceConfig.QBUseQBInvoiceNumber); } catch { throw new HttpError(HttpStatusCode.NotFound, "Cannot create invoice with provided data."); } MailNotification _mail_notification = new MailNotification(organizationId, departmentId, userId, from, recipients, subject, body); if (pdfBytes != null) { bigWebApps.bigWebDesk.Data.FileItem[] _files = new bigWebApps.bigWebDesk.Data.FileItem[1]; _files[0] = new bigWebApps.bigWebDesk.Data.FileItem(0, filename, pdfBytes.Length, DateTime.Now, string.Empty, pdfBytes); _mail_notification.AttachedFiles = _files; } string _return_string = _mail_notification.Commit(true); } catch { throw new HttpError(HttpStatusCode.NotFound, "Email error."); } } else { throw new HttpError(HttpStatusCode.NotFound, "No recepients selected."); } return(invoice); }