public static ObjectId FindExisting(DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, IDynamicRepository dynamicRepository, out bool isValidInput) { isValidInput = true; //check if the current record exists... only check for quick create ones if ((record._id == null || record._id == ObjectId.Empty) && view.Schema.UniqueIndex != null) { var filter = view.Schema.UniqueIndex.ToDictionary(v => v, v => record[v]?.ToString()); // If all filters are empty that's because we're receiving an object without a unique index, // which can't be compared if (filter.All(x => string.IsNullOrEmpty(x.Value))) { // We received something without a valid uniqueIndex isValidInput = false; } else { var existingRecords = dynamicRepository.GetAll <DynamicRecord>(view.Schema.Name, tenantId, null); var existingRecord = existingRecords.Where(e => e.Contains(filter)).ToList(); if (existingRecord != null && existingRecord.Count() > 0) { return(existingRecord.First()._id); } } } return(ObjectId.Empty); }
public static bool SendDocumentToSign(ObjectId tenantId, IDynamicRepository dynamicRepository, string fromEmail, string toEmail, string filePath) { var configuration = Utilities.Instance.GetConfiguration(); var subscriptionType = SubscriptionTypes.SignNow.ToString(); // Retrieve subscription by type...and user in the current tenant var subscription = dynamicRepository.GetAll <Subscription>(SchemaNames.Subscription.ToString(), tenantId).Select(r => (Subscription) new Subscription().Initialize <Subscription>(r.Values())) .FirstOrDefault(x => x.IsActive && x.Type.Name == subscriptionType); // Update subscription var accessToken = subscription.Token; var refreshToken = subscription.Secret; ISignNowService signNowService = new SignNowClient(tenantId, configuration.SignNowApiBaseUrl, accessToken); #region Retrieve user and extract email var userResponse = signNowService.RetrieveUser(); if (userResponse == null) { return(false); } var email = string.Empty; var userJson = JObject.Parse(userResponse); var emails = userJson.SelectTokens("emails").FirstOrDefault(); if (emails == null) { email = fromEmail; } else { email = (string)emails.FirstOrDefault(); } #endregion #region Document Signature Information dynamic documentSignatureInfo = new { fields = new[] { new { x = 370, y = 708, width = 208, height = 75, page_number = 0, role = "Customer", required = true, type = "signature" } } }; #endregion #region Invite Information dynamic inviteInfo = new { to = new[] { new { email = toEmail, role_id = "", role = "Customer", order = 1, } }, from = email, subject = configuration.SignNowInviteSubject, message = configuration.SignNowInviteMessage }; #endregion return(signNowService.SendRoleBasedInvite(filePath, documentSignatureInfo, inviteInfo)); }