public override bool Execute(BusinessRules.OrderTaskContext context) { if (context.Order.PaymentStatus == Orders.OrderPaymentStatus.Paid) { bool val = BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentComplete); if (!val) { context.Errors.Add(new BusinessRules.WorkflowMessage("Error", "An Error Occurred While Trying To Process Your Request, Please Try Again.", true)); } return val; } else { return true; } }
public OrderDtlVw2Model(BusinessRules r) : base(r) { }
protected void DataPortal_Create() { Csla.ApplicationContext.GlobalContext["Create"] = "No criteria"; BusinessRules.CheckRules(); }
public string[] GetDefaultRules() { BusinessRules.RuleSet = "default"; return(BusinessRules.GetRuleDescriptions()); }
private void DataPortal_Create() { BusinessRules.CheckRules(); }
public void TestImport() { BusinessRules businessRules = new BusinessRules(".\\Test Data\\Inventory.xml"); Assert.AreEqual(10, businessRules.sourceInventory.inventoryProducts.Count, "Unexpected number of records loaded"); }
/// <summary> /// Adds the object authorization rules. /// </summary> protected static void AddObjectAuthorizationRules() { BusinessRules.AddRule(typeof(RoleList), new IsInRole(AuthorizationActions.GetObject, "User")); AddObjectAuthorizationRulesExtend(); }
object[] IDataController.GetListOfValues(string controller, string view, DistinctValueRequest request) { SelectView(controller, view); ViewPage page = new ViewPage(request); page.ApplyDataFilter(_config.CreateDataFilter(), controller, view, request.LookupContextController, request.LookupContextView, request.LookupContextFieldName); List<object> distinctValues = new List<object>(); BusinessRules rules = _config.CreateBusinessRules(); _serverRules = rules; if (_serverRules == null) _serverRules = CreateBusinessRules(); _serverRules.Page = page; if (rules != null) rules.BeforeSelect(request); else _serverRules.ExecuteServerRules(request, ActionPhase.Before); if (_serverRules.EnableResultSet) { IDataReader reader = ExecuteResultSetReader(page); SortedDictionary<object, object> uniqueValues = new SortedDictionary<object, object>(); bool hasNull = false; while (reader.Read()) { object v = reader[request.FieldName]; if (DBNull.Value.Equals(v)) hasNull = true; else uniqueValues[v] = v; } if (hasNull) distinctValues.Add(null); foreach (object v in uniqueValues.Keys) if (distinctValues.Count < page.PageSize) distinctValues.Add(ConvertObjectToValue(v)); else break; } else using (DbConnection connection = CreateConnection()) { DbCommand command = CreateCommand(connection); ConfigureCommand(command, page, CommandConfigurationType.SelectDistinct, null); DbDataReader reader = command.ExecuteReader(); while (reader.Read() && (distinctValues.Count < page.PageSize)) { object v = reader.GetValue(0); if (!(DBNull.Value.Equals(v))) v = ConvertObjectToValue(v); distinctValues.Add(v); } reader.Close(); } if (rules != null) rules.AfterSelect(request); else _serverRules.ExecuteServerRules(request, ActionPhase.After); object[] result = distinctValues.ToArray(); EnsureJsonCompatibility(result); return result; }
/// <summary> /// Invokes all rules for the business type. /// </summary> public void CheckRules() { BusinessRules.CheckRules(); }
protected override void AddBusinessRules() { base.AddBusinessRules(); // add rules to default rule set //------------------------------------------------------------------------------------------------------------------------- //---------------------------- Address is required //------------------------------------------------------------------------------------------------------------------------- BusinessRules.AddRule(new Required(AddressProperty) { MessageText = "Customer must have name" }); BusinessRules.AddRule(new MaxLength(AddressProperty, 50) { Priority = 1, MessageText = "{0} cannot be longer than {1} chars" }); BusinessRules.AddRule(new MinLength(AddressProperty, 3) { Priority = 1, MessageText = "{0} cannot be shorter than {1} chars" }); //------------------------------------------------------------------------------------------------------------------------- //---------------------------- Num2 Larger Than Num1 //------------------------------------------------------------------------------------------------------------------------- //BusinessRules.AddRule<CustomerEdit>(Num1Property, o => o.Num1 > 3, "{0} must be larger than 3"); //BusinessRules.AddRule<CustomerEdit>(Num2Property, o => o.Num2 > Num1, () => Resources.Num2LargerThanNum1, RuleSeverity.Warning); //BusinessRules.AddRule(new Dependency(Num1Property, Num2Property)); //------------------------------------------------------------------------------------------------------------------------- //---------------------------- Compare To //------------------------------------------------------------------------------------------------------------------------- //BusinessRules.AddRule(new GreaterThanOrEqual(Num2Property, Num1Property)); //BusinessRules.AddRule(new LessThan(StartDateProperty, EndDateProperty)); //BusinessRules.AddRule(new GreaterThan(EndDateProperty, StartDateProperty)); //------------------------------------------------------------------------------------------------------------------------- //---------------------------- Name is required //------------------------------------------------------------------------------------------------------------------------- BusinessRules.AddRule(new Required(NameProperty) { MessageDelegate = () => Resources.NameRequired }); BusinessRules.AddRule(new MaxLength(NameProperty, 50) { Priority = 1, MessageDelegate = () => Resources.NameMaxLength }); //------------------------------------------------------------------------------------------------------------------------- //---------------------------- Calculated Sum //------------------------------------------------------------------------------------------------------------------------- // set up dependencies to that Sum is automatically recaclulated when PrimaryProperty is changed BusinessRules.AddRule(new Dependency(Num1Property, SumProperty)); BusinessRules.AddRule(new Dependency(Num2Property, SumProperty)); // add dependency for LessThanProperty rule on Num1 BusinessRules.AddRule(new Dependency(Num2Property, Num1Property)); BusinessRules.AddRule(new MaxValue <int>(Num1Property, 5000) { MessageText = "Num1 must be less than 5000" }); BusinessRules.AddRule(new LessThan(Num1Property, Num2Property)); //// calculates sum rule - must alwas run before MinValue with lower priority BusinessRules.AddRule(new CalcSum(SumProperty, Num1Property, Num2Property) { Priority = -1 }); BusinessRules.AddRule(new MinValue <int>(SumProperty, 1)); //------------------------------------------------------------------------------------------------------------------------- //---------------------------- Name Unique //------------------------------------------------------------------------------------------------------------------------- // ShortCircuit (ie do not run rules) for these properties when object has IsNew = false // DataAnnotation rules is always added with priority -1 so by giving ShortCircuiting rules a priority of -1 // you can also block DataAnootation rules from being executed. // The same may also be done with StopINotCanWrite to prevent validation of fields that the user is not allowed to edit. //BusinessRules.AddRule(new StopIfIsNotNew(NameProperty) { Priority = 1 }); //BusinessRules.AddRule(new Required(NameProperty)); //BusinessRules.AddRule(new MaxLength(NameProperty, 20)); //BusinessRules.AddRule(new CustomerNameExistsRule(NameProperty)); //BusinessRules.AddRule(new CustomerNameRequiredRule(NameProperty)); BusinessRules.AddRule(new IsDuplicateNameAsync(NameProperty, IdProperty)); BusinessRules.RuleSet = "CustA"; BusinessRules.AddRule(new DoAsyncRule(NameProperty)); // use default rule set BusinessRules.RuleSet = "default"; }
private void RecursiveDataBindInternal(IHierarchicalEnumerable enumerable, StringBuilder sb) { bool first = true; if (this.Site != null) { return; } foreach (object item in enumerable) { IHierarchyData data = enumerable.GetHierarchyData(item); if (null != data) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(data); if (props.Count > 0) { string title = ((string)(props["Title"].GetValue(data))); string description = ((string)(props["Description"].GetValue(data))); string url = ((string)(props["Url"].GetValue(data))); string cssClass = null; bool isPublic = false; if (item is SiteMapNode) { cssClass = ((SiteMapNode)(item))["cssClass"]; isPublic = ("true" == ((string)(((SiteMapNode)(item))["public"]))); } string roles = String.Empty; ArrayList roleList = ((ArrayList)(props["Roles"].GetValue(data))); if (roleList.Count > 0) { roles = String.Join(",", ((string[])(roleList.ToArray(typeof(string))))); } bool resourceAuthorized = true; if (resourceAuthorized) { if (first) { first = false; } else { sb.Append(","); } sb.AppendFormat("{{title:\"{0}\",url:\"{1}\"", BusinessRules.JavaScriptString(title), BusinessRules.JavaScriptString(url)); if (!(String.IsNullOrEmpty(description))) { sb.AppendFormat(",description:\"{0}\"", BusinessRules.JavaScriptString(description)); } if (url == Page.Request.RawUrl) { sb.Append(",selected:true"); } if (!(String.IsNullOrEmpty(cssClass))) { sb.AppendFormat(",cssClass:\"{0}\"", cssClass); } if (data.HasChildren) { IHierarchicalEnumerable childrenEnumerable = data.GetChildren(); if (null != childrenEnumerable) { sb.Append(",\"children\":["); RecursiveDataBindInternal(childrenEnumerable, sb); sb.Append("]"); } } sb.Append("}"); } } } } }
public override bool Rollback(BusinessRules.OrderTaskContext context) { return true; }
protected virtual BusinessRules InitBusinessRules(PageRequest request, ViewPage page) { BusinessRules rules = _config.CreateBusinessRules(); _serverRules = rules; if (_serverRules == null) _serverRules = CreateBusinessRules(); _serverRules.Page = page; _serverRules.RequiresRowCount = (page.RequiresRowCount && !((request.Inserting || request.DoesNotRequireData))); if (rules != null) rules.BeforeSelect(request); else _serverRules.ExecuteServerRules(request, ActionPhase.Before); return rules; }
public MemberSMSModel(BusinessRules r) : base(r) { }
/// <summary> /// Invokes all business rules attached at the class level of a business type. /// </summary> public void CheckObjectRules() { BusinessRules.CheckObjectRules(); }
protected override void AddBusinessRules() { base.AddBusinessRules(); BusinessRules.AddRule(new BadRule()); }
public OrderStatusLogV2ApprovalModel(BusinessRules r) : base(r) { }
protected override void AddBusinessRules() { BusinessRules.AddRule(new RuleBroken(Test1Property)); BusinessRules.AddRule(new RuleBroken(Test2Property)); }
/// <summary> /// Checks if the current user can change FolderDoc's properties. /// </summary> /// <returns><c>true</c> if the user can update the object; otherwise, <c>false</c>.</returns> public static bool CanEditObject() { return(BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.EditObject, typeof(FolderDoc))); }
/// <summary> /// Checks if the current user can retrieve RoleList's properties. /// </summary> /// <returns><c>true</c> if the user can read the object; otherwise, <c>false</c>.</returns> public static bool CanGetObject() { return(BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.GetObject, typeof(RoleList))); }
public MemberSearchModel(BusinessRules r) : base(r) { }
private void SetProperties() { ITrackStatus targetObject = Model as ITrackStatus; ICollection list = Model as ICollection; INotifyBusy busyObject = Model as INotifyBusy; bool isObjectBusy = false; if (busyObject != null && busyObject.IsBusy) { isObjectBusy = true; } // Does Model instance implement ITrackStatus if (targetObject != null) { var canDeleteInstance = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, targetObject); IsDirty = targetObject.IsDirty; IsValid = targetObject.IsValid; CanSave = CanEditObject && targetObject.IsSavable && !isObjectBusy; CanCancel = CanEditObject && targetObject.IsDirty && !isObjectBusy; CanCreate = CanCreateObject && !targetObject.IsDirty && !isObjectBusy; CanDelete = CanDeleteObject && !isObjectBusy && canDeleteInstance; CanFetch = CanGetObject && !targetObject.IsDirty && !isObjectBusy; // Set properties for List if (list == null) { CanRemove = false; CanAddNew = false; } else { Type itemType = Csla.Utilities.GetChildItemType(Model.GetType()); if (itemType == null) { CanAddNew = false; CanRemove = false; } else { CanRemove = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, itemType) && list.Count > 0 && !isObjectBusy; CanAddNew = BusinessRules.HasPermission(AuthorizationActions.CreateObject, itemType) && !isObjectBusy; } } } // Else if Model instance implement ICollection else if (list != null) { Type itemType = Csla.Utilities.GetChildItemType(Model.GetType()); if (itemType == null) { CanAddNew = false; CanRemove = false; } else { CanRemove = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, itemType) && list.Count > 0 && !isObjectBusy; CanAddNew = BusinessRules.HasPermission(AuthorizationActions.CreateObject, itemType) && !isObjectBusy; } } else { IsDirty = false; IsValid = false; CanCancel = false; CanCreate = CanCreateObject; CanDelete = false; CanFetch = CanGetObject && !IsBusy; CanSave = false; CanRemove = false; CanAddNew = false; } }
protected override void DataPortal_Create() { LoadProperty(SsnProperty, string.Empty); LoadProperty(Ssn2Property, string.Empty); BusinessRules.CheckRules(); }
/// <summary> /// The data portal_ fetch. /// </summary> /// <param name="criteria"> /// The criteria. /// </param> protected void DataPortal_Fetch(object criteria) { BusinessRules.CheckRules(); }
public string[] GetRuleDescriptions() { return(BusinessRules.GetRuleDescriptions()); }
public string[] GetTestRules() { BusinessRules.RuleSet = "test"; return(BusinessRules.GetRuleDescriptions()); }
/// <summary> /// Checks if the current user can delete a DocFolderColl object. /// </summary> /// <returns><c>true</c> if the user can delete the object; otherwise, <c>false</c>.</returns> public static bool CanDeleteObject() { return(BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.DeleteObject, typeof(DocFolderColl))); }
private void DataPortal_Create(Criteria criteria) { Csla.ApplicationContext.GlobalContext["Create"] = "Criteria"; BusinessRules.CheckRules(); }
/// <summary> /// The add object authorization rules. /// </summary> private static void AddObjectAuthorizationRules() { BusinessRules.AddRule(typeof(Root2), new IsInRole(AuthorizationActions.EditObject, "nobody")); }
/// <summary> /// Override this method in your business class to be notified when you need to set up shared business rules. /// </summary> /// <remarks> /// This method is automatically called by CSLA.NET when your object should associate /// per-type validation rules with its properties. /// </remarks> protected override void AddBusinessRules() { base.AddBusinessRules(); // Property Business Rules // RegisterDate BusinessRules.AddRule(new DateNotInFuture(RegisterDateProperty) { MessageDelegate = () => Resources.DateNotInFuture, Priority = 1 }); // DocumentType BusinessRules.AddRule(new CollapseWhiteSpace(DocumentTypeProperty) { Priority = 1 }); // DocumentReference BusinessRules.AddRule(new CollapseWhiteSpace(DocumentReferenceProperty) { Priority = 1 }); // DocumentEntity BusinessRules.AddRule(new CollapseWhiteSpace(DocumentEntityProperty) { Priority = 1 }); // DocumentDept BusinessRules.AddRule(new CollapseWhiteSpace(DocumentDeptProperty) { Priority = 1 }); // DocumentClass BusinessRules.AddRule(new ClassificationFormat(DocumentClassProperty) { Priority = 1 }); // DocumentDate BusinessRules.AddRule(new DateNotInFuture(DocumentDateProperty) { MessageDelegate = () => Resources.DateNotInFuture, Priority = 1 }); // Subject BusinessRules.AddRule(new CollapseSpace(SubjectProperty) { Priority = 1 }); // SenderName BusinessRules.AddRule(new CollapseWhiteSpace(SenderNameProperty) { Priority = 1 }); // ReceptionDate BusinessRules.AddRule(new DateNotInFuture(ReceptionDateProperty) { MessageDelegate = () => Resources.DateNotInFuture, Priority = 1 }); // RoutedTo BusinessRules.AddRule(new CollapseWhiteSpace(RoutedToProperty) { Priority = 1 }); // Notes BusinessRules.AddRule(new CollapseSpace(NotesProperty)); // ArchiveLocation BusinessRules.AddRule(new CollapseWhiteSpace(ArchiveLocationProperty)); AddBusinessRulesExtend(); }
private void DataPortal_Create() { BusinessRules.CheckRules(); Console.WriteLine("DataPortal_Create finished"); }
public new Rules.BrokenRulesCollection GetBrokenRules() { return(BusinessRules.GetBrokenRules()); }
protected static void AddObjectAuthorizationRules() { BusinessRules.AddRule(typeof(Invoice), new IsInRole(AuthorizationActions.DeleteObject, Role.FullControl.ToString())); }
public void Validate() { BusinessRules.CheckRules(); }
ActionResult IDataController.Execute(string controller, string view, ActionArgs args) { ActionResult result = new ActionResult(); SelectView(controller, view); try { _serverRules = _config.CreateBusinessRules(); if (_serverRules == null) _serverRules = CreateBusinessRules(); IActionHandler handler = ((IActionHandler)(_serverRules)); if (_config.PlugIn != null) _config.PlugIn.PreProcessArguments(args, result, CreateViewPage()); if (args.SqlCommandType != CommandConfigurationType.None) using (DbConnection connection = CreateConnection()) { DbCommand command = CreateCommand(connection, args); if ((args.SelectedValues != null) && (((args.LastCommandName == "BatchEdit") && (args.CommandName == "Update")) || ((args.CommandName == "Delete") && (args.SelectedValues.Length > 1)))) { ViewPage page = CreateViewPage(); PopulatePageFields(page); string originalCommandText = command.CommandText; foreach (string sv in args.SelectedValues) { result.Canceled = false; _serverRules.ClearBlackAndWhiteLists(); string[] key = sv.Split(','); int keyIndex = 0; foreach (FieldValue v in args.Values) { DataField field = page.FindField(v.Name); if (field != null) if (!(field.IsPrimaryKey)) v.Modified = true; else if (v.Name == field.Name) { v.OldValue = key[keyIndex]; v.Modified = false; keyIndex++; } } ExecutePreActionCommands(args, result, connection); if (handler != null) handler.BeforeSqlAction(args, result); else _serverRules.ExecuteServerRules(args, result, ActionPhase.Before); if ((result.Errors.Count == 0) && !(result.Canceled)) { ConfigureCommand(command, null, args.SqlCommandType, args.Values); result.RowsAffected = (result.RowsAffected + TransactionManager.ExecuteNonQuery(command)); if (handler != null) handler.AfterSqlAction(args, result); else _serverRules.ExecuteServerRules(args, result, ActionPhase.After); command.CommandText = originalCommandText; command.Parameters.Clear(); if (_config.PlugIn != null) _config.PlugIn.ProcessArguments(args, result, page); } } } else { ExecutePreActionCommands(args, result, connection); if (handler != null) handler.BeforeSqlAction(args, result); else _serverRules.ExecuteServerRules(args, result, ActionPhase.Before); if ((result.Errors.Count == 0) && !(result.Canceled)) { if (ConfigureCommand(command, null, args.SqlCommandType, args.Values)) { result.RowsAffected = TransactionManager.ExecuteNonQuery(args, result, CreateViewPage(), command); if (result.RowsAffected == 0) { result.RowNotFound = true; result.Errors.Add(Localizer.Replace("RecordChangedByAnotherUser", "The record has been changed by another user.")); } else ExecutePostActionCommands(args, result, connection); } if (handler != null) handler.AfterSqlAction(args, result); else _serverRules.ExecuteServerRules(args, result, ActionPhase.After); if (_config.PlugIn != null) _config.PlugIn.ProcessArguments(args, result, CreateViewPage()); } } } else if (args.CommandName.StartsWith("Export")) ExecuteDataExport(args, result); else if (args.CommandName.Equals("PopulateDynamicLookups")) PopulateDynamicLookups(args, result); else if (args.CommandName.Equals("ProcessImportFile")) ImportProcessor.Execute(args); else if (args.CommandName.Equals("Execute")) using (DbConnection connection = CreateConnection()) { DbCommand command = CreateCommand(connection, args); TransactionManager.ExecuteNonQuery(command); } else _serverRules.ProcessSpecialActions(args, result); } catch (Exception ex) { if (ex.GetType() == typeof(System.Reflection.TargetInvocationException)) ex = ex.InnerException; HandleException(ex, args, result); } result.EnsureJsonCompatibility(); return result; }