/// <summary> /// Send an <c>Email</c> message using a <c>Template</c>. /// If you do not know your template id, you can use this method with just template title. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.sendemailfromtemplaterequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="email">CRM (XRM) email entity without body and subject. Email body and subject will be replaced by specified template's properties.</param> /// <param name="templateTitle"><c>Template</c> title</param> /// <param name="regarding">Regarding object that related by template</param> /// <returns>Created record Id (<see cref="Guid"/>)</returns> public Guid Send(Entity email, string templateTitle, EntityReference regarding) { ExceptionThrow.IfNullOrEmpty(templateTitle, "templateTitle"); ExceptionThrow.IfNull(regarding, "regarding"); ExceptionThrow.IfGuidEmpty(regarding.Id, "EntityReference.Id"); ExceptionThrow.IfNullOrEmpty(regarding.LogicalName, "EntityReference.LogicalName"); ValidateEmailEntity(email); QueryExpression query = new QueryExpression("template") { ColumnSet = new ColumnSet("templateid", "templatetypecode"), Criteria = new FilterExpression() }; query.Criteria.AddCondition("title", ConditionOperator.Equal, templateTitle); query.Criteria.AddCondition("templatetypecode", ConditionOperator.Equal, regarding.LogicalName.ToLower()); EntityCollection templateCollection = this.OrganizationService.RetrieveMultiple(query); ExceptionThrow.IfNull(templateCollection, "template", string.Format("'{0}' template not exists or not related with '{1}' entity.", templateTitle, regarding.LogicalName)); ExceptionThrow.IfGreaterThan(templateCollection.Entities.Count, "template", 1, "There are more than one template with same name"); Guid templateId = templateCollection.Entities[0].Id; return(Send(email, templateId, regarding)); }
/// <summary> /// Validate <see cref="XrmRecurringAppointment"/> required fields by patterns and throws exception if values not expected. /// </summary> public void Validate() { ExceptionThrow.IfEquals(_startTime, "StartTime", DateTime.MinValue); ExceptionThrow.IfEquals(_endTime, "EndTime", DateTime.MinValue); ExceptionThrow.IfEquals(_startRangeDate, "StartRange", DateTime.MinValue); #region | Validate Recurrence Pattern | switch (_recurrencePattern) { case RecurrencePatternType.Daily: if (_isEveryWeekday) { ExceptionThrow.IfEquals(_dayOfWeeksValue, "Days Of Week", 0); ExceptionThrow.IfNegative(_dayOfWeeksValue, "Days Of Week"); ExceptionThrow.IfNotExpectedValue(_dayOfWeeksValue, "Days Of Week", 62); } else { ExceptionThrow.IfEquals(_interval, "Interval", 0); ExceptionThrow.IfNegative(_interval, "Interval"); } break; case RecurrencePatternType.Weekly: ExceptionThrow.IfEquals(_dayOfWeeksValue, "Days Of Week", 0); ExceptionThrow.IfNegative(_dayOfWeeksValue, "Days Of Week"); ExceptionThrow.IfGreaterThan(_dayOfWeeksValue, "Days Of Week", 127); ExceptionThrow.IfEquals(_interval, "Interval", 0); ExceptionThrow.IfNegative(_interval, "Interval"); break; case RecurrencePatternType.Monthly: ExceptionThrow.IfEquals(_interval, "Interval", 0); ExceptionThrow.IfNegative(_interval, "Interval"); if (_isFirstOption) { ExceptionThrow.IfEquals(_dayNumber, "Day", 0); ExceptionThrow.IfNegative(_dayNumber, "Day"); } else { ExceptionThrow.IfEquals(_dayOfWeeksValue, "Days Of Week", 0); ExceptionThrow.IfNegative(_dayOfWeeksValue, "Days Of Week"); ExceptionThrow.IfGreaterThan(_dayOfWeeksValue, "Days Of Week", 127); } break; case RecurrencePatternType.Yearly: ExceptionThrow.IfEquals(_interval, "Interval", 0); ExceptionThrow.IfNegative(_interval, "Interval"); ExceptionThrow.IfEquals((int)_month, "Month", 0); ExceptionThrow.IfNegative((int)_month, "Month"); if (_isFirstOption) { ExceptionThrow.IfEquals(_dayNumber, "Day", 0); ExceptionThrow.IfNegative(_dayNumber, "Day"); } else { ExceptionThrow.IfEquals(_dayOfWeeksValue, "Days Of Week", 0); ExceptionThrow.IfNegative(_dayOfWeeksValue, "Days Of Week"); ExceptionThrow.IfGreaterThan(_dayOfWeeksValue, "Days Of Week", 127); } break; } #endregion #region | Validate Recurrence End Pattern | switch (_recurrenceEndPattern) { case RecurrenceEndPatternType.NoEndDate: break; case RecurrenceEndPatternType.Occurrences: ExceptionThrow.IfNegative(_occurence, "Occurence"); ExceptionThrow.IfEquals(_occurence, "Occurence", 0); break; case RecurrenceEndPatternType.WithEnddate: ExceptionThrow.IfEquals(_endRangeDate, "EndRange", DateTime.MinValue); break; } #endregion }